home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / winsr173.zip / WINFRACT.C < prev    next >
C/C++ Source or Header  |  1992-07-22  |  89KB  |  2,421 lines

  1. /****************************************************************************
  2.  
  3.  
  4.     PROGRAM: winfract.c
  5.  
  6.     PURPOSE: Windows-specific main-driver code for Fractint for Windows
  7.              (look in MAINFRAC.C for the non-windows-specific code)
  8.  
  9.     Copyright (C) 1990 The Stone Soup Group.  Fractint for Windows 
  10.     may be freely copied and distributed, but may not be sold.
  11.     
  12.     We are, of course, copyrighting the code we wrote to implement
  13.     Fractint-for-Windows, and not the routines we lifted directly
  14.     or indirectly from Microsoft's Windows 3.0 Software Development Kit.
  15.  
  16. ****************************************************************************/
  17.  
  18. #include "windows.h"
  19. #include "winfract.h"
  20. #include "mathtool.h"
  21. #include "fractype.h"
  22. #include "fractint.h"
  23. #include "select.h"
  24. #include <math.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <search.h>
  28. #include <string.h>
  29. #include <time.h>
  30. #include "profile.h"
  31.  
  32. #ifndef WINVER
  33. #define WINVER 0x0300        /* assume Windows 3.0 SDK if not found */
  34. #endif
  35.  
  36. unsigned int windows_version;        /* 0x0300 = Win 3.0, 0x030A = 3.1 */
  37.  
  38. extern LPSTR win_lpCmdLine;
  39.  
  40. HANDLE hInst;
  41.  
  42. HANDLE hAccTable;                        /* handle to accelerator table */
  43. extern BOOL ZoomBarOpen;
  44. int ZoomMode;
  45.  
  46. HWND hMainWnd, hwnd;                     /* handle to main window */
  47. HWND hWndCopy;                 /* Copy of hWnd */
  48.  
  49. char far winfract_title_text[41];    /* Winfract title-bar text */
  50.  
  51. #define PALETTESIZE 256               /* dull-normal VGA                    */
  52. HANDLE hpal;                          /* palette handle                     */
  53. PAINTSTRUCT ps;                       /* paint structure                    */
  54. HDC hDC;                              /* handle to device context           */
  55. HDC hMemoryDC;                        /* handle to memory device context    */
  56. BITMAP Bitmap;                        /* bitmap structure                   */
  57. extern time_t last_time;
  58. unsigned IconWidth, IconHeight, IconSize;
  59. HANDLE hIconBitmap;
  60.  
  61. HANDLE  hPal;          /* Handle to the application's logical palette  */
  62. HANDLE  hLogPal;       /* Temporary Handle */
  63. LPLOGPALETTE pLogPal;  /* pointer to tha application's logical palette */
  64. int     iNumColors;    /* Number of colors supported by device           */
  65. int     iRasterCaps;   /* Raster capabilities                           */
  66. int     iPalSize;      /* Size of Physical palette                       */
  67.  
  68. BOOL    win_systempaletteused = FALSE;    /* flag system palette set */
  69. extern int win_syscolorindex[21];
  70. extern DWORD win_syscolorold[21];
  71. extern DWORD win_syscolornew[21];
  72.  
  73. /* MCP 6-16-91 */
  74. extern int pixelshift_per_byte;
  75. extern long pixels_per_bytem1;        /* pixels / byte - 1 (for ANDing) */
  76. extern unsigned char win_andmask[8];
  77. extern unsigned char win_notmask[8];
  78. extern unsigned char win_bitshift[8];
  79.  
  80. extern int CoordBoxOpen;
  81. extern HWND hCoordBox;
  82. extern int TrackingZoom, Zooming, ReSizing;
  83.  
  84. #define EXE_NAME_MAX_SIZE  128
  85.  
  86. BOOL       bHelp = FALSE;      /* Help mode flag; TRUE = "ON"*/
  87. HCURSOR    hHelpCursor;        /* Cursor displayed when in help mode*/
  88. char       szHelpFileName[EXE_NAME_MAX_SIZE+1];    /* Help file name*/
  89.  
  90. void MakeHelpPathName(char*);  /* Function deriving help file path */
  91.  
  92. unsigned char far win_dacbox[256][3];
  93. extern unsigned char dacbox[256][3], olddacbox[256][3];
  94. extern int colorpreloaded;
  95. extern int  colorstate;
  96.  
  97. int win_fastupdate;                   /* 0 for "normal" fast screen updates */
  98. extern int show_orbit;
  99.  
  100. int max_colors;
  101.  
  102. BOOL bTrack = FALSE;                  /* TRUE if user is selecting a region */
  103. BOOL bMove  = FALSE;
  104. BOOL bMoving = FALSE;
  105. BOOL zoomflag = FALSE;                /* TRUE if a zoom-box selected */
  106. extern POINT DragPoint;
  107. RECT Rect;
  108.  
  109. int Shape = SL_ZOOM;            /* shape to use for the selection rectangle */
  110.  
  111. /* pointers to various dialog-box routines */
  112. FARPROC lpProcAbout;
  113. FARPROC lpOpenDlg;
  114. FARPROC lpSelectFractal;
  115. FARPROC lpSelectFracParams;
  116. FARPROC lpSelectImage;
  117. FARPROC lpSelectDoodads;
  118. FARPROC lpSelectExtended;
  119. FARPROC lpSelectSavePar;
  120. FARPROC lpSelectCycle;
  121. FARPROC lpSaveAsDlg;
  122. FARPROC lpProcStatus;
  123. FARPROC lpSelect3D;
  124. FARPROC lpSelect3DPlanar;
  125. FARPROC lpSelect3DSpherical;
  126. FARPROC lpSelectIFS3D;
  127. FARPROC lpSelectFunnyGlasses;
  128. FARPROC lpSelectLightSource;
  129. FARPROC lpSelectStarfield;
  130.  
  131. extern int FileFormat;
  132. extern unsigned char readname[];
  133. extern unsigned char FileName[];
  134. extern unsigned char FormFileName[];
  135. extern unsigned char FullPathName[];
  136. extern unsigned char DefPath[];
  137. extern unsigned char LFileName[];
  138. extern unsigned char LName[];
  139. extern unsigned char far DialogTitle[];
  140. extern unsigned char DefSpec[];
  141. extern unsigned char DefExt[];
  142.  
  143. HBITMAP hBitmap, oldBitmap, oldoldbitmap;              /* working bitmaps */
  144.  
  145. HANDLE hDibInfo;        /* handle to the Device-independent bitmap */
  146. LPBITMAPINFO pDibInfo;        /* pointer to the DIB info */
  147. HANDLE hpixels;            /* handle to the DIB pixels */
  148. unsigned char huge *pixels;    /* the device-independent bitmap  pixels */
  149. extern int bytes_per_pixelline;    /* pixels/line / pixels/byte */
  150. extern long win_bitmapsize;     /* size of the DIB in bytes */
  151. extern    int    resave_flag;    /* resaving after a timed save */
  152. extern    char overwrite;     /* overwrite on/off */
  153.  
  154. HANDLE hClipboard1, hClipboard2, hClipboard3; /* handles to clipboard info */
  155. LPSTR lpClipboard1, lpClipboard2;            /* pointers to clipboard info */
  156.  
  157. int last_written_y = -2;        /* last line written */
  158. int screen_to_be_cleared = 1;    /* flag that the screen is to be cleared */
  159. int time_to_act = 0;        /* time to take some sort of action? */
  160. int time_to_restart = 0;        /* time to restart?  */
  161. int time_to_reinit = 0;         /* time to reinitialize?  */
  162. int time_to_resume = 0;        /* time to resume? */
  163. int time_to_quit = 0;           /* time to quit? */
  164. int time_to_save = 0;        /* time to save the file? */
  165. int time_to_print = 0;        /* time to print the file? */
  166. int time_to_load = 0;        /* time to load a new file? */
  167. int time_to_cycle = 0;          /* time to begin color-cycling? */
  168. int time_to_starfield = 0;      /* time to make a starfield? */
  169. int time_to_orbit = 0;          /* time to activate orbits? */
  170.  
  171. int win_3dspherical = 0;          /* spherical 3D? */
  172. int win_display3d, win_overlay3d; /* 3D flags */
  173. extern    int    init3d[20];    /* '3d=nn/nn/nn/...' values */
  174. extern    int RAY;
  175.  
  176. extern int win_cycledir, win_cyclerand, win_cycledelay;
  177.  
  178. extern int calc_status;
  179.  
  180. int xdots, ydots, colors, maxiter;
  181. int ytop, ybottom, xleft, xright;
  182. int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  183. int win_xdots, win_ydots;
  184. extern int fractype;
  185. extern double param[4];
  186. extern double xxmin, xxmax, yymin, yymax, xx3rd, yy3rd;
  187. double jxxmin, jxxmax, jyymin, jyymax, jxx3rd, jyy3rd;
  188. extern int frommandel, bitshift, biomorph;
  189. extern int maxit;
  190.  
  191. int cpu, fpu;            /* cpu, fpu flags */
  192.  
  193. extern int win_release;
  194.  
  195. char *win_choices[100];
  196. int win_numchoices, win_choicemade;
  197.  
  198. extern int onthelist[];
  199. extern int CountFractalList;
  200. extern int CurrentFractal;
  201. int MaxFormNameChoices = 80;
  202. char FormNameChoices[80][25];
  203. extern char FormName[30];
  204. extern char    IFSFileName[];    /* IFS code file */
  205. extern char    IFSName[];        /* IFS code item */
  206. double far *temp_array;
  207. HANDLE htemp_array;
  208.  
  209. HANDLE hSaveCursor;             /* the original cursor value */
  210. HANDLE hHourGlass;              /* the hourglass cursor value */
  211.  
  212. BOOL winfract_menustyle = FALSE;/* Menu style:
  213.                    FALSE = Winfract-style,
  214.                    TRUE  = Fractint-style */
  215.  
  216. /* far strings (near space is precious) */
  217. char far winfract_msg01[] = "Fractint For Windows";
  218. char far winfract_msg02[] = "WinFracMenu";
  219. char far winfract_msg03[] = "FractintForWindowsV0010";
  220. char far winfract_msg04[] = "WinfractAcc";
  221. char far winfract_msg96[] = "I'm sorry, but color-cycling \nrequires a palette-based\nvideo driver";
  222. char far winfract_msg97[] = "There isn't enough available\nmemory to run Winfract";
  223. char far winfract_msg98[] =  "This program requires Standard\nor 386-Enhanced Mode";
  224. char far winfract_msg99[] = "Not Enough Free Memory to Copy to the Clipboard";
  225.  
  226. /****************************************************************************
  227.  
  228.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  229.  
  230.     PURPOSE: calls initialization function, processes message loop
  231.  
  232. ****************************************************************************/
  233.  
  234. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  235. HANDLE hInstance;
  236. HANDLE hPrevInstance;
  237. LPSTR lpCmdLine;
  238. int nCmdShow;
  239. {
  240.     win_lpCmdLine = lpCmdLine;
  241.  
  242.     if (!hPrevInstance)
  243.         if (!InitApplication(hInstance))
  244.             return (FALSE);
  245.  
  246.     if (!InitInstance(hInstance, nCmdShow))
  247.         return (FALSE);
  248.  
  249.     fractint_main();            /* fire up the main Fractint code */
  250.     if(htemp_array) {
  251.         GlobalUnlock(htemp_array);
  252.         GlobalFree(htemp_array);
  253.     }
  254.     
  255.     wintext_destroy();        /* destroy the text window */
  256.  
  257.     DestroyWindow(hWndCopy);    /* stop everything when it returns */
  258.  
  259.     return(0);                  /* we done when 'fractint_main' returns */
  260. }
  261.  
  262. /****************************************************************************
  263.  
  264.     FUNCTION: InitApplication(HANDLE)
  265.  
  266.     PURPOSE: Initializes window data and registers window class
  267.  
  268. ****************************************************************************/
  269.  
  270. BOOL InitApplication(hInstance)
  271. HANDLE hInstance;
  272. {
  273.     WNDCLASS  wc;
  274.  
  275.     wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  276.     wc.lpfnWndProc = MainWndProc;
  277.     wc.cbClsExtra = 0;
  278.     wc.cbWndExtra = 0;
  279.     wc.hInstance = hInstance;
  280.     wc.hIcon = NULL;
  281.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  282.     wc.hbrBackground = GetStockObject(BLACK_BRUSH);
  283.     wc.lpszMenuName =  winfract_msg02;
  284.     wc.lpszClassName = winfract_msg03;
  285.  
  286.     return(RegisterClass(&wc) && RegisterMathWindows(hInstance));
  287. }
  288.  
  289.  
  290. /****************************************************************************
  291.  
  292.     FUNCTION:  InitInstance(HANDLE, int)
  293.  
  294.     PURPOSE:  Saves instance handle and creates main window
  295.  
  296. ****************************************************************************/
  297. BOOL InitInstance(hInstance, nCmdShow)
  298.     HANDLE          hInstance;
  299.     int             nCmdShow;
  300. {
  301.     DWORD WinFlags;
  302.     unsigned int version, i;
  303.     int iLoop, jLoop;
  304.     DWORD ThisColor;
  305.  
  306.     float temp;
  307.  
  308.     /* so, what kind of a computer are we on, anyway? */
  309.     WinFlags = GetWinFlags();
  310.     cpu = 88;                             /* determine the CPU type */
  311.     if (WinFlags & WF_CPU186) cpu = 186;
  312.     if (WinFlags & WF_CPU286) cpu = 286;
  313.     if (WinFlags & WF_CPU386) cpu = 386;
  314.     if (WinFlags & WF_CPU486) cpu = 386;
  315.     fpu = 0;                              /* determine the FPU type */
  316.     if (WinFlags & WF_80x87)  fpu = 87;
  317.     if (fpu && (cpu == 386))  fpu = 387;
  318.  
  319.     version = LOWORD(GetVersion());    /* which version of Windows is it? */
  320.     windows_version = ((LOBYTE(version) << 8) | HIBYTE(version));
  321.  
  322.     hInst = hInstance;
  323.  
  324.     hAccTable = LoadAccelerators(hInst, winfract_msg04);
  325.  
  326.     win_set_title_text();
  327.  
  328.     hMainWnd = hwnd = CreateWindow(
  329.         winfract_msg03,
  330.         winfract_title_text,
  331.         WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
  332.         140, 100,  /* initial locn instead of CW_USEDEFAULT, CW_USEDEFAULT, */
  333.         360, 280,  /* initial size instead of CW_USEDEFAULT, CW_USEDEFAULT, */
  334.         NULL,
  335.         NULL,
  336.         hInstance,
  337.         NULL
  338.     );
  339.  
  340.     if (!hwnd) {  /* ?? can't create the initial window! */
  341.         return (FALSE);
  342.         }
  343.  
  344.     wintext_initialize(
  345.         (HANDLE) hInstance,
  346.         (HWND) hwnd,
  347.         (LPSTR) winfract_title_text);
  348.  
  349.     /* This program doesn't run in "real" mode, so shut down right
  350.        now to keep from mucking up Windows */
  351.     if (!((WinFlags & WF_STANDARD) || (WinFlags & WF_ENHANCED))) {
  352.         MessageBox (
  353.             GetFocus(),
  354.             winfract_msg98,
  355.             winfract_msg01,
  356.             MB_ICONSTOP | MB_OK);
  357.         return(FALSE);
  358.         }
  359.     
  360.     win_xdots = xdots;
  361.     win_ydots = ydots;
  362.     maxiter = 150;                   /* and a few iterations */
  363.     xposition = yposition = 0;       /* dummy up a few pointers */
  364.     xpagesize = ypagesize = 2000;
  365.     set_win_offset();
  366.  
  367.     /* obtain an hourglass cursor */
  368.     hHourGlass  = LoadCursor(NULL, IDC_WAIT);
  369.     hSaveCursor = LoadCursor(NULL, IDC_ARROW);
  370.  
  371.     SizeWindow(hwnd);
  372.     ShowWindow(hwnd, nCmdShow);
  373.     UpdateWindow(hwnd);
  374.  
  375.     /* let's ensure that we have at lease 40K of free memory */
  376.     {
  377.     HANDLE temphandle;
  378.     if (!(temphandle = GlobalAlloc(GMEM_FIXED,40000L)) ||
  379.         !(htemp_array = GlobalAlloc(GMEM_FIXED, sizeof(double) * 8001))) {
  380.         MessageBox (
  381.             GetFocus(),
  382.             winfract_msg97,
  383.             winfract_msg01,
  384.             MB_ICONSTOP | MB_OK);
  385.         return(FALSE);
  386.         }
  387.         GlobalLock(temphandle);
  388.         GlobalUnlock(temphandle);
  389.         GlobalFree(temphandle);
  390.         temp_array = (double far *)GlobalLock(htemp_array);
  391.     }
  392.  
  393.    MakeHelpPathName(szHelpFileName);
  394.  
  395.     /* so, what kind of a display are we using, anyway? */
  396.     hDC = GetDC(NULL);
  397.     iPalSize    = GetDeviceCaps (hDC, SIZEPALETTE);
  398.     iRasterCaps = GetDeviceCaps (hDC, RASTERCAPS);
  399.     iRasterCaps = (iRasterCaps & RC_PALETTE) ? TRUE : FALSE;
  400.     if (iRasterCaps)
  401.        iNumColors = GetDeviceCaps(hDC, SIZEPALETTE);
  402.     else
  403.        iNumColors = GetDeviceCaps(hDC, NUMCOLORS);
  404.     ReleaseDC(NULL,hDC);
  405.  
  406.     /* fudges for oddball stuff (is there any?) */
  407.     /* also, note that "true color" devices return -1 for NUMCOLORS */
  408.     colors = iNumColors;
  409.     if (colors < 2 || colors > 16) colors = 256;
  410.     if (colors > 2 && colors < 16) colors = 16;
  411.     /* adjust for Windows' 20 reserved palettes in 256-color mode */
  412.     max_colors = 256;
  413.     if (colors == 256  && iNumColors >= 0) max_colors = 236;
  414.  
  415.      /* Allocate enough memory for a logical palette with
  416.       * PALETTESIZE entries and set the size and version fields
  417.       * of the logical palette structure.
  418.       */
  419.      if (!(hLogPal = GlobalAlloc (GMEM_FIXED,
  420.         (sizeof (LOGPALETTE) +
  421.         (sizeof (PALETTEENTRY) * (PALETTESIZE)))))) {
  422.         MessageBox (
  423.             GetFocus(),
  424.             winfract_msg97,
  425.             winfract_msg01,
  426.             MB_ICONSTOP | MB_OK);
  427.         return(FALSE);
  428.           }
  429.     pLogPal = (LPLOGPALETTE)GlobalLock(hLogPal); 
  430.     pLogPal->palVersion    = 0x300;
  431.     pLogPal->palNumEntries = PALETTESIZE;
  432.     /* fill in intensities for all palette entry colors */
  433.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++) {
  434.         pLogPal->palPalEntry[iLoop].peRed   = iLoop;
  435.         pLogPal->palPalEntry[iLoop].peGreen = 0;
  436.         pLogPal->palPalEntry[iLoop].peBlue  = 0;
  437.         pLogPal->palPalEntry[iLoop].peFlags = PC_EXPLICIT;
  438.         }
  439.     /* flip the ugly red color #1 with the pretty blue color #4 */
  440.     if (iNumColors < 0 || iNumColors > 4) {
  441.         pLogPal->palPalEntry[1].peRed = 4;
  442.         pLogPal->palPalEntry[4].peRed = 1;
  443.         }
  444.     /*  create a logical color palette according the information
  445.         in the LOGPALETTE structure. */
  446.     hDC = GetDC(GetFocus());
  447.     SetMapMode(hDC,MM_TEXT);
  448.     hPal = CreatePalette ((LPLOGPALETTE) pLogPal) ;
  449.     /* attempt to default to a reasonable Windows palette map */
  450.     ReleaseDC(GetFocus(),hDC);
  451.     if (ValidateLuts("defaultw.map") == 0)
  452.             spindac(0,1);
  453.     /* get the "real" colors */
  454.     hDC = GetDC(GetFocus());
  455.     SelectPalette (hDC, hPal, 1);
  456.     RealizePalette(hDC);
  457.     jLoop = iNumColors;
  458.     if (jLoop < 0) jLoop = -1;
  459.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++){
  460.         if (++jLoop >= iNumColors)
  461.             if (iNumColors > 0)
  462.                 jLoop = 0;
  463.         ThisColor = GetNearestColor (hDC, PALETTEINDEX (jLoop) );
  464.         win_dacbox[iLoop][0] = dacbox[iLoop][0] =
  465.             ((BYTE)GetRValue (ThisColor)) >> 2;
  466.         win_dacbox[iLoop][1] = dacbox[iLoop][1] =
  467.             ((BYTE)GetGValue (ThisColor)) >> 2;
  468.         win_dacbox[iLoop][2] = dacbox[iLoop][2] =
  469.             ((BYTE)GetBValue (ThisColor)) >> 2;
  470.         }
  471.     ReleaseDC(GetFocus(),hDC);
  472.  
  473.     if (dacbox[0][0] == 0 && dacbox[0][1] == 0 && dacbox[0][2] == 0 && 
  474.         dacbox[1][0] == 0 && dacbox[1][1] == 0 && dacbox[1][2] == 0) {
  475.         /* huh?? We have a black-on-black palette??? */
  476.         if (ValidateLuts("defaultw.map") == 0) {
  477.             for (iLoop = 0; iLoop < PALETTESIZE; iLoop++)
  478.                for (jLoop = 0; jLoop < 3; jLoop++)
  479.                    win_dacbox[iLoop][jLoop] = dacbox[iLoop][jLoop];
  480.             spindac(0,1);
  481.             }
  482.         }
  483.  
  484.     /* allocate a device-independent bitmap header */
  485.     if (!(hDibInfo = GlobalAlloc(GMEM_FIXED,
  486.         sizeof(BITMAPINFOHEADER)+256*sizeof(PALETTEENTRY)))) {
  487.         MessageBox (
  488.             GetFocus(),
  489.             winfract_msg97,
  490.             winfract_msg01,
  491.             MB_ICONSTOP | MB_OK);
  492.         return(FALSE);
  493.         }
  494.     pDibInfo = (LPBITMAPINFO)GlobalLock(hDibInfo);
  495.     /* fill in the header */
  496.     pDibInfo->bmiHeader.biSize  = (long)sizeof(BITMAPINFOHEADER);
  497.     pDibInfo->bmiHeader.biWidth  = win_xdots;
  498.     pDibInfo->bmiHeader.biHeight = win_ydots;
  499.     pDibInfo->bmiHeader.biSizeImage = (DWORD)win_xdots * win_ydots;
  500.     pDibInfo->bmiHeader.biPlanes = 1;
  501.     pDibInfo->bmiHeader.biBitCount = 8;
  502.     pDibInfo->bmiHeader.biCompression = BI_RGB;
  503.     pDibInfo->bmiHeader.biXPelsPerMeter = 0L;
  504.     pDibInfo->bmiHeader.biYPelsPerMeter = 0L;
  505.     pDibInfo->bmiHeader.biClrUsed = 0L;
  506.     pDibInfo->bmiHeader.biClrImportant = 0L;
  507.     default_dib_palette();
  508.  
  509.     IconWidth = GetSystemMetrics(SM_CXICON);
  510.     IconHeight = GetSystemMetrics(SM_CYICON);
  511.     IconSize = (IconWidth * IconHeight) >> pixelshift_per_byte;
  512.     hIconBitmap = GlobalAlloc(GMEM_MOVEABLE, IconSize);
  513.  
  514.     /* initialize our delay counter */
  515.     CalibrateDelay();
  516.     win_cycledelay = 15;
  517.  
  518.     /* allocate and lock a pixel array for the initial bitmap */
  519.     hpixels = (HANDLE) 0;
  520.     pixels = (char huge *) NULL;
  521.     if (hIconBitmap && clear_screen(0))
  522.         return(TRUE);
  523.  
  524.     MessageBox (
  525.         GetFocus(),
  526.         winfract_msg97,
  527.         winfract_msg01,
  528.          MB_ICONSTOP | MB_OK);
  529.  
  530.     return (FALSE);
  531.  
  532. }
  533.  
  534. void lmemcpy(char huge *to, char huge *from, long len)
  535. {
  536. long i;
  537.  
  538. for (i = 0; i < len; i++)
  539.   to[i] = from[i];
  540. }
  541.  
  542. HWND SecondaryhWnd;
  543. unsigned Secondarymessage;
  544. WORD SecondarywParam;
  545. LONG SecondarylParam;
  546.  
  547. /****************************************************************************
  548.  
  549.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  550.  
  551.     PURPOSE:  Processes messages
  552.               For some WM_COMMAND messages, may just set a flag
  553.               indicating that the fractal engine should bail out
  554.               and invoke 'SecondWndProc()' to handle them.
  555.               
  556. ****************************************************************************/
  557.  
  558. long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  559. HWND hWnd;                /* handle to main window */
  560. unsigned message;
  561. WORD wParam;
  562. LONG lParam;
  563. {
  564.  
  565.     RECT tempRect;
  566.     HMENU hMenu;
  567.  
  568.     int Return;
  569.     int i, fchoice;
  570.     extern char FractintMenusStr[];
  571.     extern char FractintPixelsStr[];
  572.  
  573.     switch (message) {
  574.  
  575.         case WM_INITMENU:
  576.            if (!iRasterCaps || iNumColors < 16) {
  577.                EnableMenuItem(GetMenu(hWnd), IDM_CYCLE, MF_DISABLED | MF_GRAYED);
  578.                }
  579.            hMenu = GetMenu(hWnd);
  580.            if (winfract_menustyle) {
  581.                CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_CHECKED);
  582.                CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_UNCHECKED);
  583.                }
  584.            else {
  585.                CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_UNCHECKED);
  586.                CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_CHECKED);
  587.                }
  588.            if (win_fastupdate)
  589.                CheckMenuItem(hMenu, IDM_PIXELS, MF_CHECKED);
  590.            else
  591.                CheckMenuItem(hMenu, IDM_PIXELS, MF_UNCHECKED);
  592.            hWndCopy = hWnd;
  593.            return (TRUE);
  594.  
  595.         case WM_LBUTTONDBLCLK:
  596.             if(Zooming) {
  597.                win_savedac();
  598.                ExecuteZoom();
  599.                }
  600.             if (bMove) {
  601.                DragPoint = MAKEPOINT(lParam);
  602.         ExecZoom:
  603.                /* End the selection */
  604.                EndSelection(DragPoint, &Rect);
  605.                ClearSelection(hWnd, &Rect, Shape);
  606.            win_title_text(-1);
  607.  
  608.                if(PtInRect(&Rect, DragPoint)) {
  609.                   if (abs(Rect.bottom - Rect.top ) > 5 &&
  610.                       abs(Rect.right  - Rect.left) > 5) {
  611.                         double xd, yd, z;
  612.                         extern POINT Center, ZoomDim;
  613.                         extern double delxx, delyy;
  614.         
  615.             z = (double)(ZoomDim.x << 1) / xdots;
  616.             if(ZoomMode == IDM_ZOOMOUT) {
  617.                 z = 1.0 / z;
  618.                 xd = (xxmin + xxmax) / 2 - (delxx * z * (Center.x + win_xoffset - (xdots/2)));
  619.                 yd = (yymin + yymax) / 2 + (delxx * z * (Center.y + win_yoffset - (ydots/2)));
  620.                 }
  621.             else {
  622.                 xd = xxmin + (delxx * (Center.x + win_xoffset));  /* BDT 11/6/91 */
  623.                 yd = yymax - (delyy * (Center.y + win_yoffset));  /* BDT 11/6/91 */
  624.                 }
  625.             xxmin = xd - (delxx * z * (xdots / 2));
  626.             xxmax = xd + (delxx * z * (xdots / 2));
  627.             yymin = yd - (delyy * z * (ydots / 2));
  628.             yymax = yd + (delyy * z * (ydots / 2));
  629.             }
  630.  
  631.                       zoomflag = TRUE;
  632.                       win_savedac();
  633.                       time_to_restart = 1;
  634.                       time_to_cycle = 0;
  635.                       calc_status = 0;
  636.                   }
  637.  
  638.                   bMove = FALSE;
  639.                   bMoving = FALSE;
  640.                   bTrack = FALSE;
  641.                }
  642.  
  643.             break;
  644.  
  645.         case WM_LBUTTONDOWN:           /* message: left mouse button pressed */
  646.  
  647.             /* Start selection of region */
  648.  
  649.             if(bMove)
  650.             {
  651.                DragPoint = MAKEPOINT(lParam);
  652.                bMoving   = PtInRect(&Rect, DragPoint);
  653.                if(bMoving)
  654.                   SetCapture(hWnd);
  655.             }
  656.             else if(Zooming)
  657.                StartZoomTracking(lParam);
  658.             else if(ZoomMode == IDM_ZOOMIN || ZoomMode == IDM_ZOOMOUT)
  659.             {
  660.            win_title_text(3);
  661.                bTrack = TRUE;
  662.                bMoving = FALSE;
  663.                bMove = FALSE;
  664.                SetRectEmpty(&Rect);
  665.                StartSelection(hWnd, MAKEPOINT(lParam), &Rect,
  666.                    (wParam & MK_SHIFT) ? (SL_EXTEND | Shape) : Shape);
  667.             }
  668.             break;
  669.  
  670.         case WM_MOUSEMOVE:                        /* message: mouse movement */
  671.  
  672.             /* Update the selection region */
  673.  
  674.             if (bTrack || bMoving)
  675.                 UpdateSelection(hWnd, MAKEPOINT(lParam), &Rect, Shape);
  676.             if(CoordBoxOpen)
  677.                 UpdateCoordBox(lParam);
  678.             if(TrackingZoom)
  679.                TrackZoom(lParam);
  680.             break;
  681.  
  682.         case WM_LBUTTONUP:            /* message: left mouse button released */
  683.  
  684.             if(bTrack)
  685.             {
  686.                bTrack = FALSE;
  687.                bMove = TRUE;
  688.                ReleaseCapture();
  689.                if (abs(Rect.bottom - Rect.top ) <= 5 ||
  690.                    abs(Rect.right  - Rect.left) <= 5) {
  691.                    /* Zoom Box is too small - kill it off */
  692.                    ClearSelection(hWnd, &Rect, Shape);
  693.                win_title_text(-1);
  694.                    bMove = bMoving = bTrack = FALSE;
  695.                    }
  696.             }
  697.             else if(bMoving)
  698.             {
  699.                bMoving = FALSE;
  700.                ReleaseCapture();
  701.             }
  702.             else if(TrackingZoom)
  703.                EndZoom(lParam);
  704.             break;
  705.  
  706.         case WM_RBUTTONUP:
  707.             {
  708.             int xx, yy;
  709.             win_kill_all_zooming();
  710.             xx = LOWORD(lParam);
  711.             yy = HIWORD(lParam);
  712.             xx += win_xoffset;
  713.             yy += win_yoffset;
  714.             if (xx >= xdots || yy >= ydots) 
  715.                 break;
  716.             if (fractalspecific[fractype].tojulia != NOFRACTAL
  717.                 && param[0] == 0.0 && param[1] == 0.0) {
  718.                 /* switch to corresponding Julia set */
  719.                 fractype = fractalspecific[fractype].tojulia;
  720.                 curfractalspecific = &fractalspecific[fractype];
  721.                 param[0] = xxmin + (xxmax - xxmin) * xx / xdots;
  722.                 param[1] = yymax - (yymax - yymin) * yy / ydots;
  723.                 jxxmin = xxmin; jxxmax = xxmax;
  724.                 jyymax = yymax; jyymin = yymin;
  725.                 jxx3rd = xx3rd; jyy3rd = yy3rd;
  726.                 frommandel = 1;
  727.                 xxmin = fractalspecific[fractype].xmin;
  728.                 xxmax = fractalspecific[fractype].xmax;
  729.                 yymin = fractalspecific[fractype].ymin;
  730.                 yymax = fractalspecific[fractype].ymax;
  731.                 xx3rd = xxmin;
  732.                 yy3rd = yymin;
  733.                 if(biomorph != -1 && bitshift != 29) {
  734.                    xxmin *= 3.0;
  735.                    xxmax *= 3.0;
  736.                    yymin *= 3.0;
  737.                    yymax *= 3.0;
  738.                    xx3rd *= 3.0;
  739.                    yy3rd *= 3.0;
  740.                    }
  741.                 calc_status = 0;
  742.                 }
  743.             else if (fractalspecific[fractype].tomandel != NOFRACTAL) {
  744.                 /* switch to corresponding Mandel set */
  745.                 fractype = fractalspecific[fractype].tomandel;
  746.                 curfractalspecific = &fractalspecific[fractype];
  747.                 if (frommandel) {
  748.                     xxmin = jxxmin;  xxmax = jxxmax;
  749.                     yymin = jyymin;  yymax = jyymax;
  750.                     xx3rd = jxx3rd;  yy3rd = jyy3rd;
  751.                     }
  752.                 else {
  753.                     double ccreal,ccimag;
  754.                     ccreal = (fractalspecific[fractype].xmax - fractalspecific[fractype].xmin) / 2;
  755.                     ccimag = (fractalspecific[fractype].ymax - fractalspecific[fractype].ymin) / 2;
  756.                     xxmin = xx3rd = param[0] - ccreal;
  757.                     xxmax = param[0] + ccreal;
  758.                     yymin = yy3rd = param[1] - ccimag;
  759.                     yymax = param[1] + ccimag;
  760.                     }
  761.                 frommandel = 0;
  762.                 param[0] = 0;
  763.                 param[1] = 0;
  764.                 calc_status = 0;
  765.                 }
  766.             else {
  767.                 buzzer(2); /* can't switch */
  768.                 break;
  769.                 }
  770.  
  771.             ytop    = 0;
  772.             ybottom = ydots-1;
  773.             xleft   = 0;
  774.             xright  = xdots-1;
  775.  
  776.             time_to_restart  = 1;
  777.             time_to_cycle = 0;
  778.             calc_status = 0;
  779.             }
  780.             break;
  781.  
  782.         case WM_CREATE:
  783.  
  784.             /* the scroll bars are hard-coded to 100 possible values */
  785.             xposition = yposition = 0;      /* initial scroll-bar positions */
  786.             SetScrollRange(hWnd,SB_HORZ,0,100,FALSE);
  787.             SetScrollRange(hWnd,SB_VERT,0,100,FALSE);
  788.             SetScrollPos(hWnd,SB_HORZ,xposition,TRUE);
  789.             SetScrollPos(hWnd,SB_VERT,yposition,TRUE);
  790.             InitializeParameters(hWnd);
  791.             break;
  792.  
  793.         case WM_SIZE:
  794.             win_kill_all_zooming();
  795.             xpagesize = LOWORD(lParam);        /* remember the window size */
  796.             ypagesize = HIWORD(lParam);
  797.         set_win_offset();
  798.             if(!ReSizing && !IsIconic(hWnd))
  799.            ReSizeWindow(hWnd);
  800.             break;
  801.  
  802.         case WM_MOVE:
  803.             SaveWindowPosition(hWnd, WinfractPosStr);
  804.             break;
  805.  
  806.         case WM_HSCROLL:
  807.             win_kill_all_zooming();
  808.             switch (wParam) {
  809.                case SB_LINEDOWN:       xposition += 1; break;
  810.                case SB_LINEUP:         xposition -= 1; break;
  811.                case SB_PAGEDOWN:       xposition += 10; break;
  812.                case SB_PAGEUP:         xposition -= 10; break;
  813.                case SB_THUMBPOSITION:  xposition = LOWORD(lParam);
  814.                default:                break;
  815.                }
  816.             if (xposition > 100) xposition = 100;
  817.             if (xposition <     0) xposition = 0;
  818.             if (xposition != GetScrollPos(hWnd,SB_HORZ)) {
  819.                SetScrollPos(hWnd,SB_HORZ,xposition,TRUE);
  820.                InvalidateRect(hWnd,NULL,TRUE);
  821.                }
  822.             set_win_offset();
  823.            break;
  824.         case WM_VSCROLL:
  825.             win_kill_all_zooming();
  826.             switch (wParam) {
  827.                case SB_LINEDOWN:       yposition += 1; break;
  828.                case SB_LINEUP:         yposition -= 1; break;
  829.                case SB_PAGEDOWN:       yposition += 10; break;
  830.                case SB_PAGEUP:         yposition -= 10; break;
  831.                case SB_THUMBPOSITION:  yposition = LOWORD(lParam);
  832.                default:                break;
  833.                }
  834.             if (yposition > 100) yposition = 100;
  835.             if (yposition <     0) yposition = 0;
  836.             if (yposition != GetScrollPos(hWnd,SB_VERT)) {
  837.                SetScrollPos(hWnd,SB_VERT,yposition,TRUE);
  838.                InvalidateRect(hWnd,NULL,TRUE);
  839.                }
  840.             set_win_offset();
  841.             break;
  842.  
  843.         case WM_CLOSE:
  844.             message = WM_COMMAND;
  845.             wParam  = IDM_EXIT;
  846.             goto GlobalExit;
  847.  
  848.         case WM_PAINT:
  849.             if (screen_to_be_cleared && last_written_y < 0) {
  850.                  /* an empty window */
  851.                  screen_to_be_cleared = 0;
  852.                  GetUpdateRect(hWnd, &tempRect, TRUE);
  853.                  hDC = BeginPaint(hWnd,&ps);
  854.                  if (last_written_y == -2)
  855.                      last_written_y = -1;
  856.                  else
  857.                      BitBlt(hDC, 0, 0, xdots, ydots,
  858.                          NULL, 0, 0, BLACKNESS);
  859.                  ValidateRect(hWnd, &tempRect);
  860.                  EndPaint(hWnd,&ps);
  861.                  break;
  862.                  }
  863.             if(IsIconic(hWnd)) {
  864.                int x, y;
  865.                LPSTR icon;
  866.                long lx, ly, dlx, dly;
  867.                DWORD tSize, tWidth, tHeight;
  868.  
  869.                if((icon = GlobalLock(hIconBitmap)) == NULL)
  870.                   break;
  871.  
  872.                dlx = ((long)xdots << 8) / IconWidth;
  873.                dly = ((long)ydots << 8) / IconHeight;
  874.                for(ly = y = 0; y < IconHeight; y++, ly += dly)
  875.                {
  876.                   for(lx = x = 0; x < IconWidth; x++, lx += dlx)
  877.                   {
  878.                      unsigned ix, iy;
  879.                      unsigned char color;
  880.  
  881.                      ix = lx >> 8;
  882.                      iy = ly >> 8;
  883.                      color = getcolor(ix, iy);
  884.  
  885.                      ix = IconWidth - y - 1;
  886.                      ix = (ix * IconWidth) + x;
  887.                      iy = ix & pixels_per_bytem1;
  888.                      ix = ix >> pixelshift_per_byte;
  889.                      icon[ix] = (icon[ix] & win_notmask[iy]) +
  890.                                (color << win_bitshift[iy]);
  891.                   }
  892.                }
  893.  
  894.                hDC = BeginPaint(hWnd, &ps);
  895.  
  896.                SelectPalette (hDC, hPal, 0);
  897.                RealizePalette(hDC);
  898.  
  899.                tSize   = pDibInfo->bmiHeader.biSizeImage;
  900.                tHeight = pDibInfo->bmiHeader.biHeight;
  901.                tWidth  = pDibInfo->bmiHeader.biWidth;
  902.  
  903.                pDibInfo->bmiHeader.biSizeImage = IconSize;
  904.                pDibInfo->bmiHeader.biHeight    = IconHeight;
  905.                pDibInfo->bmiHeader.biWidth     = IconWidth;
  906.  
  907.                SetDIBitsToDevice(hDC,
  908.                        2, 2,
  909.                        IconWidth, IconHeight,
  910.                        0, 0,
  911.                        0, IconHeight,
  912.                        icon, (LPBITMAPINFO)pDibInfo,
  913.                        DIB_PAL_COLORS);
  914.  
  915.                pDibInfo->bmiHeader.biSizeImage = tSize;
  916.                pDibInfo->bmiHeader.biHeight    = tHeight;
  917.                pDibInfo->bmiHeader.biWidth     = tWidth;
  918.  
  919.                GlobalUnlock(hIconBitmap);
  920.  
  921.                EndPaint(hWnd, &ps);
  922.                break;
  923.             }
  924.             screen_to_be_cleared = 0;
  925.             GetUpdateRect(hWnd, &tempRect, FALSE);
  926.             if (Zooming)
  927.                 PaintMathTools();
  928.             if (bTrack || bMove || bMoving)
  929.                 UpdateSelection(hWnd, DragPoint, &Rect, Shape);
  930.             hDC = BeginPaint(hWnd,&ps);
  931.             if (last_written_y >= 0) {
  932.               int top, bottom, left, right, xcount, ycount;
  933.               /* bit-blit the invalidated bitmap area */
  934.               int fromleft, fromtop, fromright, frombottom;
  935.               long firstpixel;
  936.               top    = tempRect.top;
  937.               bottom = tempRect.bottom;
  938.               left   = tempRect.left;
  939.               right  = tempRect.right;
  940.               if (bottom >  ydots) bottom = ydots;
  941.               if (right  >= xdots) right  = xdots-1;
  942.               if (top    >  ydots) top    = ydots;
  943.               if (left   >= xdots) left   = xdots;
  944.               xcount = right  - left + 1;
  945.               ycount = bottom - top;
  946.               fromleft  = left  + win_xoffset;
  947.               fromtop   = win_ydots - bottom - win_yoffset;
  948.               if (left < xdots && top < ydots) {
  949.                   SelectPalette (hDC, hPal, 0);
  950.                   RealizePalette(hDC);
  951.                   SetMapMode(hDC,MM_TEXT);
  952.                   SetDIBitsToDevice(hDC,
  953.                        left, top,
  954.                        xcount, ycount,
  955.                        fromleft, fromtop,
  956.                        0, ydots,
  957.                        (LPSTR)pixels, (LPBITMAPINFO)pDibInfo,
  958.                        DIB_PAL_COLORS);
  959.                   }
  960.               }
  961.             ValidateRect(hWnd, &tempRect);
  962.             EndPaint(hWnd,&ps);
  963.             if (bTrack || bMove || bMoving)
  964.                 UpdateSelection(hWnd, DragPoint, &Rect, Shape);
  965.             if (Zooming)
  966.                 PaintMathTools();
  967.             last_time = time(NULL);  /* reset the "end-paint" time */
  968.             break;
  969.  
  970.         case WM_DESTROY:
  971.             win_kill_all_zooming();
  972.             if (win_systempaletteused)
  973.                 win_stop_cycling();
  974.             SaveParameters(hWnd);
  975.             /* delete the handle to the logical palette if it has any
  976.                color entries and quit. */
  977.             if (pLogPal->palNumEntries)
  978.                 DeleteObject (hPal);
  979.             time_to_quit = 1;
  980.             time_to_cycle = 0;
  981.             WinHelp(hWnd,szHelpFileName,HELP_QUIT,0L);
  982.             GlobalFree(hIconBitmap);
  983.             PostQuitMessage(0);
  984.             hWndCopy = hWnd;
  985.             break;
  986.  
  987.         case WM_ACTIVATE:
  988.             if (!wParam) {  /* app. is being de-activated */
  989.                 if (win_systempaletteused)
  990.                     win_stop_cycling();
  991.                 break;
  992.                 }
  993.  
  994.         case WM_QUERYNEWPALETTE:
  995.             /* If palette realization causes a palette change,
  996.              * we need to do a full redraw.
  997.              */
  998.              if (last_written_y >= 0) {
  999.                  hDC = GetDC (hWnd);
  1000.                  SelectPalette (hDC, hPal, 0);
  1001.                  i = RealizePalette(hDC);
  1002.                  ReleaseDC (hWnd, hDC);
  1003.                  if (i) {
  1004.                      InvalidateRect (hWnd, (LPRECT) (NULL), 1);
  1005.                      return 1;
  1006.                      }
  1007.                  else
  1008.                      return FALSE;
  1009.                  }
  1010.              else
  1011.                  return FALSE;
  1012.  
  1013.         case WM_PALETTECHANGED:
  1014.             if (wParam != hWnd){
  1015.                 if (last_written_y >= 0) {
  1016.                     hDC = GetDC (hWnd);
  1017.                     SelectPalette (hDC, hPal, 0);
  1018.                     i = RealizePalette (hDC);
  1019.                     if (i)
  1020.                         UpdateColors (hDC);
  1021.                     else
  1022.                         InvalidateRect (hWnd, (LPRECT) (NULL), 1);
  1023.                     ReleaseDC (hWnd, hDC);
  1024.                     }
  1025.                 }
  1026.             break;
  1027.  
  1028.         case WM_COMMAND:
  1029.  
  1030. GlobalExit:            
  1031.             switch (wParam) {
  1032.  
  1033.               /* Help menu items */
  1034.  
  1035.                case IDM_HELP_INDEX:
  1036.                case IDF_HELP_INDEX:
  1037.                    WinHelp(hWnd,szHelpFileName,HELP_INDEX,0L);
  1038.                    break;
  1039.  
  1040.                case IDM_HELP_FRACTINT:
  1041.                case IDF_HELP_FRACTINT:
  1042.                    fractint_help();
  1043.                    break;
  1044.  
  1045.                case IDM_HELP_KEYBOARD:
  1046.            WinHelp(hWnd,szHelpFileName,HELP_KEY,(DWORD)(LPSTR)"keys");
  1047.                    break;
  1048.  
  1049.                case IDM_HELP_HELP:
  1050.            WinHelp(hWnd,"WINHELP.HLP",HELP_INDEX,0L);
  1051.                    break;
  1052.  
  1053.                 case IDM_ABOUT:
  1054.                     lpProcAbout = MakeProcInstance(About, hInst);
  1055.                     DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
  1056.                     FreeProcInstance(lpProcAbout);
  1057.                     break;
  1058.  
  1059.                 /* View menu items */
  1060.  
  1061.                 case IDF_STATUS:
  1062.                     if (winfract_menustyle) {    /* Fractint prompts */
  1063.                         tab_display();
  1064.                         break;
  1065.                         }
  1066.                 case IDS_STATUS:
  1067.                     lpProcStatus = MakeProcInstance(Status, hInst);
  1068.                     DialogBox(hInst, "ShowStatus", hWnd, lpProcStatus);
  1069.                     FreeProcInstance(lpProcStatus);
  1070.                     break;
  1071.             
  1072.                 case IDF_FRACTINTSTYLE:
  1073.                     winfract_menustyle = TRUE;
  1074.             hMenu = GetMenu(hWnd);
  1075.             CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_CHECKED);
  1076.             CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_UNCHECKED);
  1077.                     SaveParamSwitch(FractintMenusStr, winfract_menustyle);
  1078.                     break;
  1079.             
  1080.                 case IDF_WINFRACTSTYLE:
  1081.                     winfract_menustyle = FALSE;
  1082.             hMenu = GetMenu(hWnd);
  1083.             CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_UNCHECKED);
  1084.             CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_CHECKED);
  1085.                     SaveParamSwitch(FractintMenusStr, winfract_menustyle);
  1086.                     break;
  1087.             
  1088.                /* Color-Cycling (and Zooming) hotkeys */
  1089.                
  1090.                case IDF_HOTCYCLERAND:
  1091.                    if(Zooming) {
  1092.                       win_savedac();
  1093.                       ExecuteZoom();
  1094.                       }
  1095.                    else if(bMove)
  1096.                    {
  1097.                        extern POINT Center;
  1098.  
  1099.                        DragPoint = Center;
  1100.                        goto ExecZoom;
  1101.                    }
  1102.                    else if (win_oktocycle()) {
  1103.                        win_kill_all_zooming();
  1104.                        time_to_cycle = 1;
  1105.                        win_cyclerand = 2;
  1106.                        colorstate = 1;
  1107.                        }
  1108.                    break;
  1109.  
  1110.                case IDF_HOTNOZOOM:
  1111.                   win_kill_all_zooming();
  1112.                   if(Zooming)
  1113.                      CancelZoom();
  1114.                   else if(bMove)
  1115.                   {
  1116.                      extern POINT Center;
  1117.  
  1118.                      EndSelection(Center, &Rect);
  1119.  
  1120.                      ClearSelection(hWnd, &Rect, Shape);
  1121.                      bMove = bMoving = bTrack = FALSE;
  1122.              win_title_text(-1);
  1123.                   }
  1124.                   break;
  1125.  
  1126.                case IDF_HOTCYCLEON:
  1127.                /* Space/etc.. toggles Color-cycling parameters */
  1128.                    win_kill_all_zooming();
  1129.                    if (time_to_cycle == 1) {
  1130.                        time_to_resume = 1;
  1131.                        time_to_cycle = 0;
  1132.                        }
  1133.                    else
  1134.                        if (win_oktocycle()) {
  1135.                             time_to_cycle = 1;
  1136.                             colorstate = 1;
  1137.                             }
  1138.                    break;
  1139.                    
  1140.                case IDF_HOTCYCLERIGHT: 
  1141.                    win_kill_all_zooming();
  1142.                    if (win_oktocycle()) {
  1143.                        time_to_cycle = 1;
  1144.                        win_cycledir = -1;
  1145.                        colorstate = 1;
  1146.                        }
  1147.                    break;
  1148.  
  1149.                case IDF_HOTCYCLELEFT: 
  1150.                    win_kill_all_zooming();
  1151.                    if (win_oktocycle()) {
  1152.                        time_to_cycle = 1;
  1153.                        win_cycledir = 1;
  1154.                        colorstate = 1;
  1155.                        }
  1156.                    break;
  1157.                    
  1158.                case IDF_HOTCYCLERSTEP: 
  1159.                    if (win_oktocycle()) {
  1160.                        time_to_cycle = 0;
  1161.                        win_cycledir = -1;
  1162.                        colorstate = 1;
  1163.                        spindac(win_cycledir,1);
  1164.                        }
  1165.                    break;
  1166.                    
  1167.                case IDF_HOTCYCLELSTEP: 
  1168.                    win_kill_all_zooming();
  1169.                    if (win_oktocycle()) {
  1170.                        time_to_cycle = 0;
  1171.                        win_cycledir = 1;
  1172.                        colorstate = 1;
  1173.                        spindac(win_cycledir,1);
  1174.                        }
  1175.                    break;
  1176.  
  1177.                case IDF_HOTCYCLEFAST: 
  1178.                    win_kill_all_zooming();
  1179.                    if (time_to_cycle != 0 && win_cycledelay > 4)
  1180.                        win_cycledelay -= 5;
  1181.                    break;
  1182.  
  1183.                case IDF_HOTCYCLESLOW: 
  1184.                    win_kill_all_zooming();
  1185.                    if (time_to_cycle != 0 && win_cycledelay < 100)
  1186.                        win_cycledelay += 5;
  1187.                    break;
  1188.  
  1189.         case IDM_ORBITS:
  1190.             /* toggle orbits only if in pixel-by-pixel mode */
  1191.             if (win_fastupdate)
  1192.                         time_to_orbit = 1;
  1193.                 break;
  1194.                    
  1195.                 /* the following commands all cause a flag to be set
  1196.                    which causes the main fractal engine to return to
  1197.                    its main level, call SecondaryWndProc(), and then
  1198.                    either resume, restart, or exit */
  1199.                 case IDM_EXIT:
  1200.                 case IDM_OPEN:
  1201.                 case IDF_OPEN:
  1202.                 case IDM_NEW:
  1203.                 case IDM_SAVE:
  1204.                 case IDF_SAVE:
  1205.                 case IDM_SAVEAS:
  1206.                 case IDM_PRINT:
  1207.                 case IDF_PRINT:
  1208.                 case IDM_3D:
  1209.                 case IDF_3D:
  1210.                 case IDM_3DOVER:
  1211.                 case IDF_3DOVER:
  1212.                 case IDM_PARFILE:
  1213.                 case IDF_PARFILE:
  1214.                 case IDM_SAVEPAR:
  1215.                 case IDF_SAVEPAR:
  1216.                 case IDM_COPY:
  1217.                 case IDC_EDIT:
  1218.                 case IDM_FORMULA:
  1219.                 case IDF_FORMULA:
  1220.                 case IDM_DOODADX:
  1221.                 case IDF_DOODADX:
  1222.                 case IDM_DOODADY:
  1223.                 case IDF_DOODADY:
  1224.             case IDM_DOODADZ:
  1225.                 case IDF_DOODADZ:
  1226.         case IDM_IFS3D:
  1227.                 case IDF_IFS3D:
  1228.                 case IDM_RESTART:
  1229.                 case IDF_RESTART:
  1230.                 case IDM_STARFIELD:
  1231.                 case IDF_STARFIELD:
  1232.                 case IDM_IMAGE:
  1233.                 case IDF_IMAGE:
  1234.                 case IDM_COORD:
  1235.         case IDM_SIZING:
  1236.                 case IDM_PIXELS:
  1237.                 case IDF_MAPIN:
  1238.                 case IDF_MAPOUT:
  1239.                 case IDM_MAPIN:
  1240.                 case IDM_MAPOUT:
  1241.                 case IDF_CYCLE:
  1242.                 case IDM_CYCLE:
  1243.                 case IDM_MATH_TOOLS:
  1244.                 case IDM_ZOOMIN:
  1245.                 case IDM_ZOOMOUT:
  1246.                 case IDM_ZOOM:
  1247.                     win_kill_all_zooming();
  1248.                     time_to_cycle = 0;
  1249.                     SecondaryhWnd = hWnd;
  1250.                     Secondarymessage = message;
  1251.                     SecondarywParam = wParam;
  1252.                     SecondarylParam = lParam;
  1253.                     time_to_act = 1;
  1254.                     break;
  1255.  
  1256.             } 
  1257.             break;
  1258.  
  1259.         default:
  1260.             return (DefWindowProc(hWnd, message, wParam, lParam));
  1261.     }
  1262.     return (NULL);
  1263. }
  1264.  
  1265. /****************************************************************************
  1266.  
  1267.     FUNCTION: SecondaryWndProc()
  1268.  
  1269.     PURPOSE:  Processes messages *after* the fractal engine exits
  1270.  
  1271. ****************************************************************************/
  1272.  
  1273. void SecondaryWndProc()
  1274. {
  1275.     HWND hWnd;                /* handle to main window */
  1276.     unsigned message;
  1277.     WORD wParam;
  1278.     LONG lParam;
  1279.  
  1280.     RECT tempRect;
  1281.     HMENU hMenu;
  1282.  
  1283.     int Return;
  1284.     int i, fchoice;
  1285.     extern char FractintMenusStr[];
  1286.     extern char FractintPixelsStr[];
  1287.  
  1288.     hWnd    = SecondaryhWnd;
  1289.     message = Secondarymessage;
  1290.     wParam  = SecondarywParam;
  1291.     lParam  = SecondarylParam;
  1292.  
  1293.     switch (message) {
  1294.  
  1295.         case WM_COMMAND:
  1296.             
  1297.             switch (wParam) {
  1298.  
  1299.                 /* File menu items */
  1300.                 
  1301.                 case IDF_OPEN:
  1302.                 case IDF_3D:
  1303.                 case IDF_3DOVER:
  1304.                     if (winfract_menustyle) {    /* Fractint prompts */
  1305.                         extern int display3d, overlay3d;
  1306.                         extern int tabmode, helpmode, initbatch;
  1307.                         extern char gifmask[];
  1308.                         int showfile;
  1309.                         char *hdg;
  1310.                         
  1311.                         win_kill_all_zooming();
  1312.                         time_to_resume = 1;
  1313.                         initbatch = 0;
  1314.                         display3d = 0;
  1315.                         overlay3d = 0;
  1316.                         if (wParam == IDM_3D || wParam == IDM_3DOVER
  1317.                             || wParam == IDF_3D || wParam == IDF_3DOVER)
  1318.                             display3d = 1;
  1319.                         if (wParam == IDM_3DOVER || wParam == IDF_3DOVER)
  1320.                             overlay3d = 1;
  1321.                         win_display3d = 0;
  1322.                         win_overlay3d = 0;
  1323.                         stackscreen();
  1324.                         tabmode = 0;
  1325.                         showfile = -1;
  1326.                         while (showfile <= 0) {        /* image is to be loaded */
  1327.                             if (overlay3d)
  1328.                                 hdg = "Select File for 3D Overlay";
  1329.                             else if (display3d)
  1330.                                 hdg = "Select File for 3D Transform";
  1331.                             else
  1332.                                 hdg = "Select File to Restore";
  1333.                             if (showfile < 0 &&
  1334.                                 getafilename(hdg,gifmask,readname) < 0) {
  1335.                             showfile = 1;             /* cancelled */
  1336.                             break;
  1337.                             }
  1338.                             showfile = 0;
  1339.                             tabmode = 1;
  1340.                             if (read_overlay() == 0)         /* read hdr, get video mode */
  1341.                             break;              /* got it, exit */
  1342.                             showfile = -1;             /* retry */
  1343.                             }
  1344.                         if (!showfile) {
  1345.                             lstrcpy(FileName, readname);
  1346.                             time_to_load = 1;
  1347.                             time_to_cycle = 0;
  1348.                             if (wParam == IDM_3D || wParam == IDM_3DOVER
  1349.                                 || wParam == IDF_3D || wParam == IDF_3DOVER)
  1350.                                 win_display3d = 1;
  1351.                             if (wParam == IDM_3DOVER || wParam == IDF_3DOVER)
  1352.                                 win_overlay3d = 1;
  1353.                             }
  1354.                         tabmode = 1;
  1355.                         unstackscreen();
  1356.                         break;
  1357.                         }
  1358.                 case IDM_NEW:
  1359.                 case IDM_OPEN:
  1360.                 case IDM_3D:
  1361.                 case IDM_3DOVER:
  1362.                     win_display3d = 0;
  1363.                     win_overlay3d = 0;
  1364.                     /* Call OpenDlg() to get the filename */
  1365.                     lstrcpy(DialogTitle,"Select a File to Open");
  1366.                     if (wParam == IDM_3D || wParam == IDF_3D)
  1367.                         lstrcpy(DialogTitle,"Select a File for 3D");
  1368.                     if (wParam == IDM_3DOVER || wParam == IDF_3DOVER)
  1369.                         lstrcpy(DialogTitle,"Select a File for 3D Overlay");
  1370.                     lstrcpy(FileName, readname);
  1371.                     lstrcpy(DefSpec,"*.gif");
  1372.                     lstrcpy(DefExt,".gif");
  1373.                     lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1374.                     Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1375.                     FreeProcInstance(lpOpenDlg);
  1376.                     if (Return && (wParam == IDM_3D || wParam == IDM_3DOVER)) {
  1377.                 extern int glassestype;
  1378.                         lpSelect3D = MakeProcInstance(
  1379.                             (FARPROC) Select3D, hInst);
  1380.                         Return = DialogBox(hInst, "Select3D",
  1381.                              hWnd, lpSelect3D);
  1382.                         FreeProcInstance(lpSelect3D);
  1383.                          if (glassestype) {
  1384.                              int Return2;
  1385.                              lpSelectFunnyGlasses = MakeProcInstance(
  1386.                                  (FARPROC) SelectFunnyGlasses, hInst);
  1387.                              Return2 = DialogBox(hInst, "SelectFunnyGlasses",
  1388.                                  hWnd, lpSelectFunnyGlasses);
  1389.                              FreeProcInstance(lpSelectFunnyGlasses);
  1390.                              check_funnyglasses_name();
  1391.                              }
  1392.                         if (Return && !win_3dspherical) {
  1393.                             lpSelect3DPlanar = MakeProcInstance(
  1394.                                 (FARPROC) Select3DPlanar, hInst);
  1395.                             Return = DialogBox(hInst, "Select3DPlanar",
  1396.                                  hWnd, lpSelect3DPlanar);
  1397.                             FreeProcInstance(lpSelect3DPlanar);
  1398.                             }
  1399.                         if (Return && win_3dspherical) {
  1400.                             lpSelect3DSpherical = MakeProcInstance(
  1401.                                 (FARPROC) Select3DSpherical, hInst);
  1402.                             Return = DialogBox(hInst, "Select3DSpherical",
  1403.                                  hWnd, lpSelect3DSpherical);
  1404.                             FreeProcInstance(lpSelect3DSpherical);
  1405.                             }
  1406.                         if (Return && (ILLUMINE || RAY)) {
  1407.                             lpSelectLightSource = MakeProcInstance(
  1408.                                 (FARPROC) SelectLightSource, hInst);
  1409.                             Return = DialogBox(hInst, "SelectLightSource",
  1410.                                  hWnd, lpSelectLightSource);
  1411.                             FreeProcInstance(lpSelectLightSource);
  1412.                             }
  1413.                         }
  1414.                     if (Return) {
  1415.                         lstrcpy(readname,FileName);
  1416.                         time_to_load = 1;
  1417.                         win_kill_all_zooming();
  1418.                         time_to_cycle = 0;
  1419.                         if (wParam == IDM_3D || wParam == IDM_3DOVER
  1420.                          || wParam == IDF_3D || wParam == IDF_3DOVER)
  1421.                             win_display3d = 1;
  1422.                         if (wParam == IDM_3DOVER || wParam == IDF_3DOVER)
  1423.                             win_overlay3d = 1;
  1424.                         }
  1425.                     break;
  1426.  
  1427.                 case IDF_SAVE:
  1428.                     if (winfract_menustyle) {    /* Fractint prompts */
  1429.                         /* (no change) */
  1430.                         }
  1431.                 case IDM_SAVE:
  1432.                 case IDM_SAVEAS:
  1433.                     /* Call the SaveAsDlg() function to get the new filename */
  1434.                     lstrcpy(DialogTitle,"Select a File to Save");
  1435.                     lstrcpy(FileName, readname);
  1436.  
  1437.                     /* MCP 10-27-91, Moved to DIALOG.C
  1438.                     lstrcpy(DefSpec,"*.gif");
  1439.                     lstrcpy(DefExt,".gif");
  1440.                     */
  1441.  
  1442.                     lpSaveAsDlg = MakeProcInstance(SaveAsDlg, hInst);
  1443.                     DialogBox(hInst, "SaveAs", hWnd, lpSaveAsDlg);
  1444.                     FreeProcInstance(lpSaveAsDlg);
  1445.                     if (time_to_save)
  1446.                     {
  1447.                        time_to_cycle = 0;
  1448.                        wsprintf(StatusTitle, "Saving:  %s", (LPSTR)FullPathName);
  1449.                        OpenStatusBox(hWnd, hInst);
  1450.                        resave_flag = overwrite = 1;
  1451.                     }
  1452.                     break;
  1453.  
  1454.                 case IDF_PRINT:
  1455.                     if (winfract_menustyle) {    /* Fractint prompts */
  1456.                         /* (no change) */
  1457.                         }
  1458.                 case IDM_PRINT:
  1459.                     time_to_print = 1;
  1460.                     time_to_cycle = 0;
  1461.                     break;
  1462.  
  1463.                 case IDM_PARFILE:
  1464. winfract_loadpar:
  1465.                     {
  1466.                     FILE *parmfile;
  1467.                     extern char CommandFile[];
  1468.                     extern char CommandName[];
  1469.                     long point;
  1470.                     
  1471.                     win_kill_all_zooming();
  1472.                     lstrcpy(DialogTitle,"Select a Parameter File");
  1473.                     lstrcpy(FileName, CommandFile);
  1474.                     lstrcpy(DefSpec,"*.par");
  1475.                     lstrcpy(DefExt,".par");
  1476.                     lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1477.                     Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1478.                     FreeProcInstance(lpOpenDlg);
  1479.                     if (Return) {
  1480.                         lstrcpy(LFileName, FileName);
  1481.                         lstrcpy(CommandFile, FileName);
  1482.                         get_lsys_name();
  1483.                         lstrcpy(DialogTitle,"Select a Parameter Entry");
  1484.                         win_choicemade = 0;
  1485.                         lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1486.                         Return = DialogBox(hInst, "SelectFractal",
  1487.                             hWnd, lpSelectFractal);
  1488.                         FreeProcInstance(lpSelectFractal);
  1489.                         if (Return) { 
  1490.                             parmfile = fopen(CommandFile,"rb");
  1491.                             memcpy((char *)&point,
  1492.                                 (char *)&win_choices[win_choicemade][21],
  1493.                                 4);
  1494.                             fseek(parmfile,point,SEEK_SET);
  1495.                             Return = load_commands(parmfile);
  1496.                             }
  1497.                         if (Return) {
  1498.                             if (xx3rd != xxmin || yy3rd != yymin)
  1499.                                 stopmsg(0," This image uses a skewed zoom-box,\n a feature not available in Winfract.\n All Skewness has been dropped"); 
  1500.                             if (colorpreloaded)
  1501.                                 win_savedac();
  1502.                         maxiter = maxit;
  1503.                     time_to_restart = 1;
  1504.                     time_to_cycle = 0;
  1505.                     calc_status = 0;
  1506.                             }
  1507.                         }
  1508.                     break;
  1509.                     }
  1510.  
  1511.                 case IDM_SAVEPAR:
  1512.                     win_kill_all_zooming();
  1513.             lpSelectSavePar = MakeProcInstance(SelectSavePar, hInst);
  1514.             Return = DialogBox(hInst, "SelectSavePar",
  1515.              hWnd, lpSelectSavePar);
  1516.             FreeProcInstance(lpSelectSavePar);
  1517.             if (Return) {
  1518.                 time_to_resume = 1;
  1519.                 win_make_batch_file();
  1520.              }
  1521.                     break;
  1522.  
  1523.                 case IDF_SAVEPAR:
  1524.                     win_kill_all_zooming();
  1525.                     time_to_resume = 1;
  1526.                     make_batch_file();
  1527.                     break;
  1528.                    
  1529.                 case IDM_COPY:
  1530.                    /* allocate the memory for the BITMAPINFO structure 
  1531.                       (followed by the bitmap bits) */
  1532.                    if (!(hClipboard1 = GlobalAlloc(GMEM_FIXED,
  1533.                    sizeof(BITMAPINFOHEADER)+colors*sizeof(PALETTEENTRY)
  1534.                    + win_bitmapsize))) {
  1535.                         cant_clip();
  1536.                         return;
  1537.                         }
  1538.                     if (!(lpClipboard1 =
  1539.                         (LPSTR) GlobalLock(hClipboard1))) {
  1540.                         GlobalFree(hClipboard1);
  1541.                         cant_clip();
  1542.                         return;
  1543.                         }
  1544.                     rgb_dib_palette();
  1545.                     lmemcpy((char huge *)lpClipboard1, (char huge *)pDibInfo,
  1546.                         sizeof(BITMAPINFOHEADER)+colors*sizeof(RGBQUAD)
  1547.                         );
  1548.                     lpClipboard1 += 
  1549.                         (sizeof(BITMAPINFOHEADER))+
  1550.                         (colors*sizeof(RGBQUAD));
  1551.                     lmemcpy((char huge *)lpClipboard1, (char huge *)pixels,
  1552.                         win_bitmapsize);
  1553.  
  1554.                     GlobalUnlock(hClipboard1);
  1555.  
  1556.                    /* allocate the memory for the palette info */
  1557.                    if (!lpClipboard2) {
  1558.                        if (!(hClipboard2 = GlobalAlloc (GMEM_FIXED,
  1559.                            (sizeof (LOGPALETTE) +
  1560.                            (sizeof (PALETTEENTRY) * (PALETTESIZE)))))) {
  1561.                             GlobalFree(hClipboard1);
  1562.                             cant_clip();
  1563.                             return;
  1564.                             }
  1565.                         if (!(lpClipboard2 = 
  1566.                             (LPSTR) GlobalLock(hClipboard2))) {
  1567.                             GlobalFree(hClipboard1);
  1568.                             GlobalFree(hClipboard2);
  1569.                             cant_clip();
  1570.                             return;
  1571.                             }
  1572.                        }
  1573.                    /* fill in the palette info */
  1574.                    lpClipboard2[0] = 0;
  1575.                    lpClipboard2[1] = 3;
  1576.                    lpClipboard2[2] = 0;
  1577.                    lpClipboard2[3] = 1;
  1578.                    lmemcpy((char huge *)&lpClipboard2[4],
  1579.                         (char huge *)&pDibInfo->bmiColors[0],
  1580.                         PALETTESIZE*sizeof(RGBQUAD)
  1581.                         );
  1582.                    hClipboard3 = CreatePalette ((LPLOGPALETTE) lpClipboard2);
  1583.  
  1584.                     hDC = GetDC(hWnd);
  1585.                     hBitmap = CreateDIBitmap(hDC, &pDibInfo->bmiHeader,
  1586.                               CBM_INIT, (LPSTR)pixels, pDibInfo,
  1587.                               DIB_RGB_COLORS);
  1588.                     ReleaseDC(hWnd, hDC);
  1589.  
  1590.                     if (OpenClipboard(hWnd)) {
  1591.                         EmptyClipboard();
  1592.                         SetClipboardData(CF_PALETTE, hClipboard3);
  1593.                         SetClipboardData(CF_DIB, hClipboard1);
  1594.                         if(hBitmap)
  1595.                           SetClipboardData(CF_BITMAP, hBitmap);
  1596.                         CloseClipboard();
  1597.                         }
  1598.  
  1599.                     default_dib_palette();
  1600.  
  1601.                     break;
  1602.  
  1603.                 case IDM_EXIT:
  1604.                     win_kill_all_zooming();
  1605.                     time_to_quit = 1;
  1606.                     time_to_cycle = 0;
  1607.                     ValidateRect(hWnd, NULL);
  1608.                     hWndCopy = hWnd;
  1609.                     /* the main routine will actually call 'DestroyWindow()' */
  1610.                     break;
  1611.  
  1612.                 /* Fractals menu items */
  1613.  
  1614.                 case IDF_FORMULA:
  1615.                     if (winfract_menustyle) {    /* Fractint prompts */
  1616.                         win_kill_all_zooming();
  1617.                         time_to_resume = 1;
  1618.                     stackscreen();
  1619.             i = get_fracttype();
  1620.                     unstackscreen();
  1621.                     SetFocus(hWnd);
  1622.                     if (i == 0) {        /* time to redraw? */
  1623.                     time_to_restart = 1;
  1624.                     time_to_cycle = 0;
  1625.                     calc_status = 0;
  1626.                     }
  1627.                     break;
  1628.                         }
  1629.                 case IDM_FORMULA:
  1630.                     lstrcpy(DialogTitle,"Select a Fractal Formula");
  1631.                     win_kill_all_zooming();
  1632.                     win_numchoices = CountFractalList;
  1633.                     win_choicemade = 0;
  1634.                     CurrentFractal = fractype;
  1635.                     for (i = 0; i < win_numchoices; i++) {
  1636.                         win_choices[i] = fractalspecific[onthelist[i]].name;
  1637.                         if (onthelist[i] == fractype ||
  1638.                             fractalspecific[onthelist[i]].tofloat == fractype)
  1639.                             win_choicemade = i;
  1640.                         }
  1641.                     lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1642.                     Return = DialogBox(hInst, "SelectFractal",
  1643.                         hWnd, lpSelectFractal);
  1644.                     FreeProcInstance(lpSelectFractal);
  1645.                     fchoice = win_choicemade;
  1646.                     if (Return && (onthelist[fchoice] == IFS ||
  1647.                         onthelist[fchoice] == IFS3D)) {
  1648.                         lstrcpy(DialogTitle,"Select an IFS Filename");
  1649.                         lstrcpy(FileName, IFSFileName);
  1650.                         lstrcpy(DefSpec,"*.ifs");
  1651.                         lstrcpy(DefExt,".ifs");
  1652.                         lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1653.                         Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1654.                         FreeProcInstance(lpOpenDlg);
  1655.                         if (Return) {
  1656.                             lstrcpy(IFSFileName, FileName);
  1657.                             lstrcpy(FormFileName, FileName);
  1658.                             get_formula_names();
  1659.                             lstrcpy(DialogTitle,"Select an IFS type");
  1660.                             win_choicemade = 0;
  1661.                             lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1662.                             Return = DialogBox(hInst, "SelectFractal",
  1663.                                 hWnd, lpSelectFractal);
  1664.                             FreeProcInstance(lpSelectFractal);
  1665.                             if (Return) {
  1666.                                 lstrcpy(IFSName, win_choices[win_choicemade]);
  1667.                                 Return = ! ifsload();
  1668.                                 }
  1669.                             }
  1670.                         }
  1671.                     if (Return && (onthelist[fchoice] == FORMULA || 
  1672.                         onthelist[fchoice] == FFORMULA)) {
  1673.                         /* obtain the formula filename */
  1674.                         lstrcpy(DialogTitle,"Select a Formula File");
  1675.                         lstrcpy(FileName, FormFileName);
  1676.                         lstrcpy(DefSpec,"*.frm");
  1677.                         lstrcpy(DefExt,".frm");
  1678.                         lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1679.                         Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1680.                         FreeProcInstance(lpOpenDlg);
  1681.                         if (Return) {
  1682.                             lstrcpy(FormFileName, FileName);
  1683.                             get_formula_names();
  1684.                             lstrcpy(DialogTitle,"Select a Formula");
  1685.                             win_choicemade = 0;
  1686.                             lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1687.                             Return = DialogBox(hInst, "SelectFractal",
  1688.                                 hWnd, lpSelectFractal);
  1689.                             FreeProcInstance(lpSelectFractal);
  1690.                             if (Return) 
  1691.                                 Return = parse_formula_names();
  1692.                             }
  1693.                         }
  1694.                     if (Return && (onthelist[fchoice] == LSYSTEM)) {
  1695.                         /* obtain the lsystem formula filename */
  1696.                         lstrcpy(DialogTitle,"Select an Lsystem File");
  1697.                         lstrcpy(FileName, LFileName);
  1698.                         lstrcpy(DefSpec,"*.l");
  1699.                         lstrcpy(DefExt,".l");
  1700.                         lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1701.                         Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1702.                         FreeProcInstance(lpOpenDlg);
  1703.                         if (Return) {
  1704.                             lstrcpy(LFileName, FileName);
  1705.                             get_lsys_name();
  1706.                             lstrcpy(DialogTitle,"Select a Formula");
  1707.                             win_choicemade = 0;
  1708.                             lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1709.                             Return = DialogBox(hInst, "SelectFractal",
  1710.                                 hWnd, lpSelectFractal);
  1711.                             FreeProcInstance(lpSelectFractal);
  1712.                             if (Return) {
  1713.                                 lstrcpy(LName, win_choices[win_choicemade]);
  1714.                                 Return = !LLoad();
  1715.                                 }
  1716.                             }
  1717.                         }
  1718.                     if (Return) {
  1719.                         CurrentFractal = onthelist[fchoice];
  1720.                         curfractalspecific = &fractalspecific[CurrentFractal];
  1721.                         set_default_parms();
  1722.                         lpSelectFracParams = MakeProcInstance(SelectFracParams,
  1723.                             hInst);
  1724.                         Return = DialogBox(hInst, "SelectFracParams",
  1725.                             hWnd, lpSelectFracParams);
  1726.                         FreeProcInstance(lpSelectFracParams);
  1727.                         }
  1728.                     if (Return) {
  1729.                         time_to_reinit = 1;
  1730.                         time_to_cycle = 0;
  1731.                         calc_status = 0;
  1732.                         }
  1733.                     break;
  1734.  
  1735.                 case IDF_PARFILE:
  1736.                     if (!winfract_menustyle) {    /* winfract prompts */
  1737.                         goto winfract_loadpar; /* for now */
  1738.                         }
  1739.                 case IDF_DOODADX:
  1740.                     if (!winfract_menustyle)   /* Windows menus */
  1741.                         goto winfract_xmenu;   /* for now */
  1742.                 case IDF_DOODADY:
  1743.                     if (!winfract_menustyle)   /* Windows menus */
  1744.                         goto winfract_ymenu;   /* for now */
  1745.                 case IDF_DOODADZ:
  1746.                     if (!winfract_menustyle)   /* Windows menus */
  1747.                         goto winfract_zmenu;   /* for now */
  1748.  
  1749.                     if (winfract_menustyle) {    /* fractint prompts */
  1750.                         win_kill_all_zooming();
  1751.                         time_to_resume = 1;
  1752.                     stackscreen();
  1753.                     maxiter = maxit;
  1754.                         if (wParam == IDF_DOODADX || wParam == IDM_DOODADX)
  1755.                             i = get_toggles();
  1756.                         else if (wParam == IDF_DOODADY || wParam == IDM_DOODADY)
  1757.                             i = get_toggles2();
  1758.                         else if (wParam == IDF_DOODADZ || wParam == IDM_DOODADZ)
  1759.                             i = get_fract_params(1);
  1760.                         else {
  1761.                 i = get_commands();
  1762.                             if (xx3rd != xxmin || yy3rd != yymin)
  1763.                                 stopmsg(0," This image uses a skewed zoom-box,\n a feature not available in Winfract.\n All Skewness has been dropped"); 
  1764.                 if (colorpreloaded)
  1765.                     win_savedac();
  1766.                 }
  1767.                     unstackscreen();
  1768.                     SetFocus(hWnd);
  1769.                         time_to_cycle = 0;
  1770.                     if (i > 0) {        /* time to redraw? */
  1771.                         maxiter = maxit;
  1772.                     time_to_restart = 1;
  1773.                     calc_status = 0;
  1774.                     }
  1775.                     break;
  1776.                    }
  1777.  
  1778.                 case IDM_DOODADX:
  1779. winfract_xmenu:
  1780.             lpSelectDoodads = MakeProcInstance(SelectDoodads, hInst);
  1781.             Return = DialogBox(hInst, "SelectDoodads",
  1782.                 hWnd, lpSelectDoodads);
  1783.             FreeProcInstance(lpSelectDoodads);
  1784.             if (Return) {
  1785.                                 win_kill_all_zooming();
  1786.                 win_savedac();
  1787.                 time_to_restart = 1;
  1788.                                 time_to_cycle = 0;
  1789.                                 calc_status = 0;
  1790.                 }
  1791.                         break;
  1792.  
  1793.                 case IDM_DOODADY:
  1794. winfract_ymenu:
  1795.             lpSelectExtended = MakeProcInstance(SelectExtended, hInst);
  1796.             Return = DialogBox(hInst, "SelectExtended",
  1797.                 hWnd, lpSelectExtended);
  1798.             FreeProcInstance(lpSelectExtended);
  1799.             if (Return) {
  1800.                                 win_kill_all_zooming();
  1801.                 win_savedac();
  1802.                 time_to_restart = 1;
  1803.                                 time_to_cycle = 0;
  1804.                                 calc_status = 0;
  1805.                 }
  1806.                         break;
  1807.  
  1808.            case IDM_DOODADZ:
  1809. winfract_zmenu:
  1810.             CurrentFractal = fractype;
  1811.                     lpSelectFracParams = MakeProcInstance(SelectFracParams,
  1812.                         hInst);
  1813.                     Return = DialogBox(hInst, "SelectFracParams",
  1814.                         hWnd, lpSelectFracParams);
  1815.                     FreeProcInstance(lpSelectFracParams);
  1816.                     if (Return) {
  1817.                         win_kill_all_zooming();
  1818.             win_savedac();
  1819.                         time_to_reinit = 1;
  1820.                         time_to_cycle = 0;
  1821.                         calc_status = 0;
  1822.                         }
  1823.               break;
  1824.  
  1825.         case IDF_IFS3D:
  1826.                     if (winfract_menustyle) {    /* Fractint prompts */
  1827.                         extern int display3d, overlay3d;
  1828.                         extern int tabmode, helpmode, initbatch;
  1829.                         extern char gifmask[];
  1830.                         int showfile;
  1831.                         tabmode = 0;
  1832.                         if (get_fract3d_params() >= 0) {
  1833.                             win_kill_all_zooming();
  1834.                             time_to_restart = 1;
  1835.                             }
  1836.                         tabmode = 1;
  1837.                         break;
  1838.                         }
  1839.         case IDM_IFS3D:
  1840.             {
  1841.             extern int glassestype;
  1842.                     lpSelectIFS3D = MakeProcInstance(
  1843.                         (FARPROC) SelectIFS3D, hInst);
  1844.                     Return = DialogBox(hInst, "SelectIFS3D",
  1845.                          hWnd, lpSelectIFS3D);
  1846.                     FreeProcInstance(lpSelectIFS3D);
  1847.                     if (Return) {
  1848.                          win_kill_all_zooming();
  1849.                          time_to_restart = 1;
  1850.                          if (glassestype) {
  1851.                              lpSelectFunnyGlasses = MakeProcInstance(
  1852.                                  (FARPROC) SelectFunnyGlasses, hInst);
  1853.                              Return = DialogBox(hInst, "SelectFunnyGlasses",
  1854.                                  hWnd, lpSelectFunnyGlasses);
  1855.                              FreeProcInstance(lpSelectFunnyGlasses);
  1856.                              check_funnyglasses_name();
  1857.                              }
  1858.                          }
  1859.                     break;
  1860.                     }
  1861.  
  1862.                case IDM_RESTART:
  1863.                case IDF_RESTART:
  1864.                    time_to_reinit  = 2;
  1865.                    time_to_cycle = 0;
  1866.                    calc_status = 0;
  1867.                    break;
  1868.  
  1869.                case IDF_STARFIELD:
  1870.                    if (winfract_menustyle) {    /* fractint prompts */
  1871.                        if (get_starfield_params() >= 0) {
  1872.                            win_kill_all_zooming();
  1873.                            time_to_starfield = 1;
  1874.                            time_to_cycle = 0;
  1875.                            calc_status = 0;
  1876.                            }
  1877.                        break;
  1878.                        }
  1879.                case IDM_STARFIELD:
  1880.                    lpSelectStarfield = MakeProcInstance(
  1881.                        (FARPROC) SelectStarfield, hInst);
  1882.                    Return = DialogBox(hInst, "Starfield",
  1883.                         hWnd, lpSelectStarfield);
  1884.                    FreeProcInstance(lpSelectStarfield);
  1885.                    if (Return) {
  1886.                        win_kill_all_zooming();
  1887.                        time_to_starfield = 1;
  1888.                        time_to_cycle = 0;
  1889.                        calc_status = 0;
  1890.                        }
  1891.                    break;
  1892.  
  1893.                 /* View menu items */
  1894.  
  1895.                 case IDF_IMAGE:
  1896.                     if (winfract_menustyle) {    /* Fractint prompts */
  1897.                         /* (no change) */
  1898.                         }
  1899.                 case IDM_IMAGE:
  1900.                         win_kill_all_zooming();
  1901.             lpSelectImage = MakeProcInstance(SelectImage, hInst);
  1902.             Return = DialogBox(hInst, "SelectImage",
  1903.                 hWnd, lpSelectImage);
  1904.             FreeProcInstance(lpSelectImage);
  1905.             if (Return) {
  1906.                 time_to_restart = 1;
  1907.                                 time_to_cycle = 0;
  1908.                                 calc_status = 0;
  1909.                 }
  1910.             ReSizeWindow(hWnd);
  1911.                         break;
  1912.  
  1913.                 case IDM_MATH_TOOLS:
  1914.                     MathToolBox(hWnd);
  1915.                     break;
  1916.  
  1917.                 case IDM_ZOOMOUT:
  1918.                 case IDM_ZOOMIN:
  1919.                     if(ZoomBarOpen)
  1920.                        ZoomBar(hWnd);
  1921.                     else
  1922.                        CheckMenuItem(GetMenu(hWnd), ZoomMode, MF_UNCHECKED);
  1923.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  1924.                     ZoomMode = wParam;
  1925.                     break;
  1926.  
  1927.                 case IDM_ZOOM:
  1928.                     if(!ZoomBarOpen)
  1929.                        CheckMenuItem(GetMenu(hWnd), ZoomMode, MF_UNCHECKED);
  1930.                     win_kill_all_zooming();
  1931.                     ZoomBar(hWnd);
  1932.                     break;
  1933.  
  1934.                 case IDM_COORD:
  1935.                     CoordinateBox(hWnd);
  1936.                     break;
  1937.  
  1938.         case IDM_SIZING:
  1939.                     win_kill_all_zooming();
  1940.             WindowSizing(hWnd);
  1941.             break;
  1942.  
  1943.                 case IDM_PIXELS:
  1944.                     {
  1945.                     BOOL profile_fastupdate;
  1946.             hMenu = GetMenu(hWnd);
  1947.                     if (win_fastupdate) {
  1948.                         win_fastupdate = 0;
  1949.                         /* if disabling p-by-p, disable orbits, too */
  1950.                         if (show_orbit)
  1951.                             time_to_orbit = 1;
  1952.                         profile_fastupdate = FALSE;
  1953.                         CheckMenuItem(hMenu, IDM_PIXELS, MF_UNCHECKED);
  1954.                         }
  1955.                     else {
  1956.                         win_fastupdate = 2;
  1957.                         profile_fastupdate = TRUE;
  1958.                         CheckMenuItem(hMenu, IDM_PIXELS, MF_CHECKED);
  1959.                         }
  1960.                     SaveParamSwitch(FractintPixelsStr, profile_fastupdate);
  1961.                     }
  1962.                     break;
  1963.  
  1964.                 case IDF_STATUS:
  1965.                     if (winfract_menustyle) {    /* Fractint prompts */
  1966.                         tab_display();
  1967.                         break;
  1968.                         }
  1969.                 case IDS_STATUS:
  1970.                     lpProcStatus = MakeProcInstance(Status, hInst);
  1971.                     DialogBox(hInst, "ShowStatus", hWnd, lpProcStatus);
  1972.                     FreeProcInstance(lpProcStatus);
  1973.                     break;
  1974.  
  1975.                 /* Colors menu items */
  1976.  
  1977.                 case IDF_MAPIN:
  1978.                     if (winfract_menustyle) {  /* fractint-style prompts */
  1979.                         win_kill_all_zooming();
  1980.                         time_to_resume = 1;
  1981.                         time_to_cycle = 0;
  1982.                         if (wParam == IDF_MAPIN)
  1983.                             load_palette();
  1984.                         else
  1985.                             save_palette();
  1986.                         spindac(0,1);
  1987.                         break;
  1988.                         }
  1989.                 case IDF_MAPOUT:
  1990.                 case IDM_MAPIN:
  1991.                 case IDM_MAPOUT:
  1992.                     /* Call OpenDlg() to get the filename */
  1993.                     lstrcpy(DialogTitle,"Select a Palette File");
  1994.                     lstrcpy(FileName, "default");
  1995.                     if (wParam == IDM_MAPOUT || wParam == IDF_MAPOUT)
  1996.                         lstrcpy(FileName, "mymap");
  1997.                     lstrcpy(DefSpec,"*.map");
  1998.                     lstrcpy(DefExt,".map");
  1999.                     lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  2000.                     Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  2001.                     FreeProcInstance(lpOpenDlg);
  2002.                     if (Return && (wParam == IDM_MAPIN || wParam == IDF_MAPIN)) {
  2003.                         win_kill_all_zooming();
  2004.                         ValidateLuts(FileName);
  2005.                         spindac(0,1);
  2006.                         }
  2007.                     if (Return && (wParam == IDM_MAPOUT || wParam == IDF_MAPOUT)) {
  2008.                         FILE *dacfile;
  2009.             dacfile = fopen(FileName,"w");
  2010.             if (dacfile == NULL) {
  2011.                 break;
  2012.                 }
  2013.             fprintf(dacfile,"  0   0   0\n");
  2014.             for (i = 1; i < 256; i++)
  2015.                 fprintf(dacfile, "%3d %3d %3d\n",
  2016.                 dacbox[i][0] << 2,
  2017.                 dacbox[i][1] << 2,
  2018.                 dacbox[i][2] << 2);
  2019.             fclose(dacfile);
  2020.                         }
  2021.                     break;
  2022.  
  2023.                 case IDF_CYCLE:
  2024.                     if (winfract_menustyle) {    /* Fractint prompts */
  2025.                         /* (no change) */
  2026.                         }
  2027.                 case IDM_CYCLE:
  2028.                     if (!win_oktocycle())
  2029.                         break;
  2030.                     win_kill_all_zooming();
  2031.                     lpSelectCycle = MakeProcInstance(SelectCycle, hInst);
  2032.                     Return = DialogBox(hInst, "SelectCycle",
  2033.                     hWnd, lpSelectCycle);
  2034.                     FreeProcInstance(lpSelectCycle);
  2035.                     break;
  2036.  
  2037.                 case IDC_EDIT:
  2038.                     if (HIWORD (lParam) == EN_ERRSPACE) {
  2039.                         MessageBox (
  2040.                               GetFocus ()
  2041.                             , "Out of memory."
  2042.                             , "Fractint For Windows"
  2043.                             , MB_ICONSTOP | MB_OK
  2044.                         );
  2045.                     }
  2046.                     break;
  2047.  
  2048.             } 
  2049.             break;
  2050.  
  2051.     }
  2052.     return;
  2053. }
  2054.  
  2055. win_set_title_text()
  2056. {
  2057.     float temp;
  2058.     char ctemp[80];
  2059.     
  2060.     temp = win_release / 100.0;
  2061.     sprintf(ctemp,"Fractint for Windows - Vers %5.2f", temp);
  2062.     lstrcpy(winfract_title_text, ctemp);
  2063. }
  2064.  
  2065. char far win_oldtitle[30];
  2066. char far win_title1[] = " (calculating)";
  2067. char far win_title2[] = " (color-cycling)";
  2068. char far win_title3[] = " (zooming)";
  2069. char far win_title4[] = " (starfield generation)";
  2070.  
  2071. win_title_text(int title)
  2072. {
  2073. char newtitle[80];
  2074.  
  2075. lstrcpy(newtitle, winfract_title_text);
  2076.  
  2077. if (title < 0) {
  2078.     lstrcat(newtitle, win_oldtitle);
  2079.     }
  2080. if (title == 0) {
  2081.     win_oldtitle[0] = 0;
  2082.     lstrcat(newtitle, win_oldtitle);
  2083.     }
  2084. if (title == 1) {
  2085.     lstrcpy(win_oldtitle, win_title1);
  2086.     lstrcat(newtitle, win_oldtitle);
  2087.     }
  2088. if (title == 2) {
  2089.     lstrcat(newtitle, win_title2);
  2090.     }
  2091. if (title == 3) {
  2092.     lstrcat(newtitle, win_title3);
  2093.     }
  2094. if (title == 4) {
  2095.     lstrcat(newtitle, win_title4);
  2096.     }
  2097.  
  2098. SetWindowText(hMainWnd, newtitle);
  2099.  
  2100. }
  2101.  
  2102. win_oktocycle()
  2103. {
  2104. if (!(iRasterCaps) || iNumColors < 16) {
  2105.     stopmsg(0,
  2106.         winfract_msg96
  2107.          );
  2108.     return(0);
  2109.     }
  2110. return(1);
  2111. }
  2112.  
  2113. extern int win_animate_flag;
  2114.  
  2115. win_stop_cycling()
  2116. {
  2117. HDC hDC;                      /* handle to device context           */
  2118.  
  2119. hDC = GetDC(GetFocus());
  2120. SetSystemPaletteUse(hDC,SYSPAL_STATIC);
  2121. ReleaseDC(GetFocus(),hDC);
  2122.  
  2123. time_to_cycle = 0;
  2124. win_animate_flag = 0;
  2125. restoredac();
  2126. win_systempaletteused = FALSE;
  2127. SetSysColors(COLOR_ENDCOLORS,(LPINT)win_syscolorindex,(LONG FAR *)win_syscolorold);
  2128. return(0);
  2129. }
  2130.  
  2131. win_kill_all_zooming()
  2132. {
  2133.     if(Zooming)
  2134.         CancelZoom();
  2135.     else if(bMove)
  2136.         {
  2137.          extern POINT Center;
  2138.  
  2139.          EndSelection(Center, &Rect);
  2140.          ClearSelection(hWndCopy, &Rect, Shape);
  2141.          bMove = bMoving = bTrack = FALSE;
  2142.          win_title_text(-1);
  2143.          }
  2144. }
  2145.  
  2146. void mono_dib_palette()
  2147. {
  2148. int i;        /* fill in the palette index values */
  2149.     for (i = 0; i < 128; i = i+2) {
  2150.         pDibInfo->bmiColors[i  ].rgbBlue      =   0;
  2151.         pDibInfo->bmiColors[i  ].rgbGreen     =   0;
  2152.         pDibInfo->bmiColors[i  ].rgbRed       =   0;
  2153.         pDibInfo->bmiColors[i  ].rgbReserved  =   0;
  2154.         pDibInfo->bmiColors[i+1].rgbBlue      = 255;
  2155.         pDibInfo->bmiColors[i+1].rgbGreen     = 255;
  2156.         pDibInfo->bmiColors[i+1].rgbRed       = 255;
  2157.         pDibInfo->bmiColors[i+1].rgbReserved  =   0;
  2158.         }
  2159. }
  2160.  
  2161. default_dib_palette()
  2162. {
  2163. int i, k;        /* fill in the palette index values */
  2164. int far *palette_values;    /* pointer to palette values */
  2165.  
  2166.     palette_values = (int far *)&pDibInfo->bmiColors[0];
  2167.     k = 0;
  2168.     for (i = 0; i < 256; i++) {
  2169.         palette_values[i] = k;
  2170.         if (++k >= iNumColors)
  2171.            if (iNumColors > 0)
  2172.                k = 0;
  2173.         }
  2174.     return(0);
  2175. }
  2176.  
  2177. rgb_dib_palette()
  2178. {
  2179. int i;        /* fill in the palette index values */
  2180.  
  2181.     for (i = 0; i < 256; i++) {
  2182.         pDibInfo->bmiColors[i].rgbRed       = dacbox[i][0] << 2;
  2183.         pDibInfo->bmiColors[i].rgbGreen     = dacbox[i][1] << 2;
  2184.         pDibInfo->bmiColors[i].rgbBlue      = dacbox[i][2] << 2;
  2185.         pDibInfo->bmiColors[i].rgbReserved  =   0;
  2186.         }
  2187.     return(0);
  2188. }
  2189.  
  2190. extern char win_funnyglasses_map_name[];
  2191.  
  2192. check_funnyglasses_name()
  2193. {
  2194.     if (win_funnyglasses_map_name[0] != 0) {
  2195.         if (ValidateLuts(win_funnyglasses_map_name) == 0) {
  2196.             win_savedac();
  2197.             }
  2198.         else {
  2199.             char temp[80];
  2200.             sprintf(temp,"Can't find map file: %s",
  2201.                 win_funnyglasses_map_name);
  2202.             stopmsg(0,temp);
  2203.             }
  2204.         }
  2205. }
  2206.  
  2207. /****************************************************************************
  2208.  
  2209.    FUNCTION:   MakeHelpPathName
  2210.  
  2211.    PURPOSE:    Winfract assumes that the .HLP help file is in the same
  2212.                directory as the Winfract executable.This function derives
  2213.                the full path name of the help file from the path of the
  2214.                executable.
  2215.  
  2216. ****************************************************************************/
  2217.  
  2218. void MakeHelpPathName(szFileName)
  2219. char * szFileName;
  2220. {
  2221.    char *  pcFileName;
  2222.    int     nFileNameLen;
  2223.  
  2224.    nFileNameLen = GetModuleFileName(hInst,szFileName,EXE_NAME_MAX_SIZE);
  2225.    pcFileName = szFileName + nFileNameLen;
  2226.  
  2227.    while (pcFileName > szFileName) {
  2228.        if (*pcFileName == '\\' || *pcFileName == ':') {
  2229.            *(++pcFileName) = '\0';
  2230.            break;
  2231.        }
  2232.    nFileNameLen--;
  2233.    pcFileName--;
  2234.    }
  2235.  
  2236.    if ((nFileNameLen+13) < EXE_NAME_MAX_SIZE) {
  2237.        lstrcat(szFileName, "winfract.hlp");
  2238.    }
  2239.  
  2240.    else {
  2241.        lstrcat(szFileName, "?");
  2242.    }
  2243.  
  2244.    return;
  2245. }
  2246.  
  2247. set_win_offset()
  2248. {
  2249. win_xoffset = ((long)xposition*((long)xdots-(long)xpagesize))/100L;
  2250. win_yoffset = ((long)yposition*((long)ydots-(long)ypagesize))/100L;
  2251. if (win_xoffset+xpagesize > xdots) win_xoffset = xdots-xpagesize;
  2252. if (win_yoffset+ypagesize > ydots) win_yoffset = ydots-ypagesize;
  2253. if (xpagesize >= xdots) win_xoffset = 0;
  2254. if (ypagesize >= ydots) win_yoffset = 0;
  2255. return(0);
  2256. }
  2257.  
  2258. win_savedac()
  2259. {
  2260.     memcpy(olddacbox,dacbox,256*3); /* save the DAC */
  2261.     colorpreloaded = 1;             /* indicate it needs to be restored */
  2262.  
  2263. }
  2264.  
  2265. /*
  2266.   Read a formula file, picking off the formula names.
  2267.   Formulas use the format "  name = { ... }  name = { ... } "
  2268. */
  2269.  
  2270. int get_formula_names()     /* get the fractal formula names */
  2271. {
  2272.    int numformulas, i;
  2273.    FILE *File;
  2274.    char msg[81], tempstring[201];
  2275.  
  2276.    FormName[0] = 0;        /* start by declaring failure */
  2277.    for (i = 0; i < MaxFormNameChoices; i++) {
  2278.       FormNameChoices[i][0] = 0;
  2279.       win_choices[i] = FormNameChoices[i];
  2280.       }
  2281.  
  2282.    if((File = fopen(FormFileName, "rt")) == NULL) {
  2283.       sprintf("I Can't find %s", FormFileName);
  2284.       stopmsg(1,msg);
  2285.       return(-1);
  2286.    }
  2287.  
  2288.    numformulas = 0;
  2289.    while(fscanf(File, " %20[^ \n\t({]", FormNameChoices[numformulas]) != EOF) {
  2290.       int c;
  2291.  
  2292.       while(c = getc(File)) {
  2293.      if(c == EOF || c == '{' || c == '\n')
  2294.         break;
  2295.       }
  2296.       if(c == EOF)
  2297.      break;
  2298.       else if(c != '\n'){
  2299.      numformulas++;
  2300.      if (numformulas >= MaxFormNameChoices) break;
  2301. skipcomments:
  2302.      if(fscanf(File, "%200[^}]", tempstring) == EOF) break;
  2303.      if (getc(File) != '}') goto skipcomments;
  2304.      if (stricmp(FormNameChoices[numformulas-1],"") == 0 ||
  2305.          stricmp(FormNameChoices[numformulas-1],"comment") == 0)
  2306.          numformulas--;
  2307.       }
  2308.    }
  2309.    fclose(File);
  2310.    win_numchoices = numformulas;
  2311.    qsort(FormNameChoices,win_numchoices,25,
  2312.          (int(*)(const void*, const void *))strcmp);
  2313.    return(0);
  2314. }
  2315.  
  2316. int parse_formula_names()     /* parse a fractal formula name */
  2317. {
  2318.  
  2319.    lstrcpy(FormName, win_choices[win_choicemade]);
  2320.  
  2321.    if (RunForm(FormName)) {
  2322.        FormName[0] = 0;     /* declare failure */
  2323.        stopmsg(0,"Can't Parse that Formula");
  2324.        return(0);
  2325.        }
  2326.  
  2327. return(1);
  2328. }
  2329.  
  2330. /* --------------------------------------------------------------------- */
  2331.  
  2332. get_lsys_name()        /* get the Lsystem formula name */
  2333. {
  2334.    int numentries, i;
  2335.    FILE *File;
  2336.    char buf[201];
  2337.    long point;
  2338.    long file_offset,name_offset;
  2339.  
  2340.    for (i = 0; i < MaxFormNameChoices; i++) {
  2341.       FormNameChoices[i][0] = 0;
  2342.       win_choices[i] = FormNameChoices[i];
  2343.       }
  2344.  
  2345.    if ((File = fopen(LFileName, "rb")) == NULL) {
  2346.       sprintf(buf,"I Can't find %s", LFileName);
  2347.       stopmsg(1,buf);
  2348.       LName[0] = 0;
  2349.       return(-1);
  2350.       }
  2351.  
  2352.    numentries = 0;
  2353.    file_offset = -1;
  2354.    while (1) {
  2355.       int c,len;
  2356.       do {
  2357.      ++file_offset;
  2358.      c = getc(File);
  2359.      } while (c == ' ' /* skip white space */
  2360.            || c == '\t' || c == '\n' || c == '\r');
  2361.       if (c == ';') {
  2362.      do {
  2363.         ++file_offset;
  2364.         c = getc(File);
  2365.         } while (c != '\n' && c != EOF && c != '\x1a');
  2366.      if (c == EOF || c == '\x1a') break;
  2367.      continue;
  2368.      }
  2369.       name_offset = file_offset;
  2370.       len = 0; /* next equiv roughly to fscanf(..,"%40[^ \n\r\t({\x1a]",buf) */
  2371.       while (c != ' ' && c != '\t' && c != '('
  2372.     && c != '{' && c != '\n' && c != '\r' && c != EOF && c != '\x1a') {
  2373.      if (len < 40) buf[len++] = c;
  2374.      c = getc(File);
  2375.      ++file_offset;
  2376.      }
  2377.       buf[len] = 0;
  2378.       while (c != '{' && c != '\n' && c != '\r' && c != EOF && c != '\x1a') {
  2379.      c = getc(File);
  2380.      ++file_offset;
  2381.      }
  2382.       if (c == '{') {
  2383.      while (c != '}' && c != EOF && c != '\x1a') {
  2384.         c = getc(File);
  2385.         ++file_offset;
  2386.         }
  2387.      if (c != '}') break;
  2388.      buf[ITEMNAMELEN] = 0;
  2389.      if (buf[0] != 0 && stricmp(buf,"comment") != 0) {
  2390.         lstrcpy(FormNameChoices[numentries],buf);
  2391.         memcpy((char *)&FormNameChoices[numentries][21],
  2392.             (char *)&name_offset,4);
  2393.         if (++numentries >= MaxFormNameChoices) {
  2394.            sprintf(buf,"Too many entries in file, first %d used",
  2395.                MaxFormNameChoices);
  2396.            stopmsg(0,buf);
  2397.            break;
  2398.            }
  2399.         }
  2400.      }
  2401.       else
  2402.      if (c == EOF || c == '\x1a') break;
  2403.       }
  2404.    fclose(File);
  2405.  
  2406.    win_numchoices = numentries;
  2407.    qsort(FormNameChoices,win_numchoices,25,
  2408.          (int(*)(const void *, const void *))strcmp);
  2409.    return(0);
  2410. }
  2411.  
  2412. cant_clip()
  2413. {
  2414. MessageBox (
  2415.    GetFocus(),
  2416.    winfract_msg99,
  2417.    winfract_msg01,
  2418.     MB_ICONSTOP | MB_OK);
  2419.     return(TRUE);
  2420. }
  2421.